MediaWiki REL1_33
phpunit.php
Go to the documentation of this file.
1#!/usr/bin/env php
2<?php
9// Set a flag which can be used to detect when other scripts have been entered
10// through this entry point or not.
11define( 'MW_PHPUNIT_TEST', true );
12
13// Start up MediaWiki in command-line mode
14require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
15
17 public function __construct() {
18 parent::__construct();
19 $this->setAllowUnregisteredOptions( true );
20 $this->addOption(
21 'debug-tests',
22 'Log testing activity to the PHPUnitCommand log channel (deprecated, always on).',
23 false, # not required
24 false # no arg needed
25 );
26 $this->addOption( 'use-filebackend', 'Use filebackend', false, true );
27 $this->addOption( 'use-bagostuff', 'Use bagostuff', false, true );
28 $this->addOption( 'use-jobqueue', 'Use jobqueue', false, true );
29 $this->addOption( 'use-normal-tables', 'Use normal DB tables.', false, false );
30 $this->addOption(
31 'reuse-db', 'Init DB only if tables are missing and keep after finish.',
32 false,
33 false
34 );
35 }
36
37 public function finalSetup() {
38 parent::finalSetup();
39
40 // Inject test autoloader
42
44 }
45
46 public function execute() {
47 // Deregister handler from MWExceptionHandler::installHandle so that PHPUnit's own handler
48 // stays in tact.
49 // Has to in execute() instead of finalSetup(), because finalSetup() runs before
50 // doMaintenance.php includes Setup.php, which calls MWExceptionHandler::installHandle().
52
53 $this->forceFormatServerArgv();
54
55 if ( !class_exists( 'PHPUnit\\Framework\\TestCase' ) ) {
56 echo "PHPUnit not found. Please install it and other dev dependencies by
57 running `composer install` in MediaWiki root directory.\n";
58 exit( 1 );
59 }
60
61 fwrite( STDERR, defined( 'HHVM_VERSION' ) ?
62 'Using HHVM ' . HHVM_VERSION . ' (' . PHP_VERSION . ")\n" :
63 'Using PHP ' . PHP_VERSION . "\n" );
64
65 // Tell PHPUnit to ignore options meant for MediaWiki
66 $ignore = [];
67 foreach ( $this->mParams as $name => $param ) {
68 if ( empty( $param['withArg'] ) ) {
69 $ignore[] = $name;
70 } else {
71 $ignore[] = "$name=";
72 }
73 }
74
75 // Pass through certain options to MediaWikiTestCase
76 $cliArgs = [];
77 foreach (
78 [
79 'use-filebackend',
80 'use-bagostuff',
81 'use-jobqueue',
82 'use-normal-tables',
83 'reuse-db'
84 ] as $name
85 ) {
86 $cliArgs[$name] = $this->getOption( $name );
87 }
88
89 $command = new MediaWikiPHPUnitCommand( $ignore, $cliArgs );
90 $command->run( $_SERVER['argv'], true );
91 }
92
93 public function getDbType() {
95 }
96
97 protected function addOption( $name, $description, $required = false,
98 $withArg = false, $shortName = false, $multiOccurrence = false
99 ) {
100 // ignore --quiet which does not really make sense for unit tests
101 if ( $name !== 'quiet' ) {
102 parent::addOption( $name, $description, $required, $withArg, $shortName, $multiOccurrence );
103 }
104 }
105
110 private function forceFormatServerArgv() {
111 $argv = [];
112 foreach ( $_SERVER['argv'] as $key => $arg ) {
113 if ( $key === 0 ) {
114 $argv[0] = $arg;
115 } elseif ( strstr( $arg, '=' ) ) {
116 foreach ( explode( '=', $arg, 2 ) as $argPart ) {
117 $argv[] = $argPart;
118 }
119 } else {
120 $argv[] = $arg;
121 }
122 }
123 $_SERVER['argv'] = $argv;
124 }
125
126}
127
128$maintClass = 'PHPUnitMaintClass';
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$command
Definition cdb.php:65
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
setAllowUnregisteredOptions( $allow)
Sets whether to allow unregistered options, which are options passed to a script that do not match an...
static requireTestsAutoloader()
Call this to set up the autoloader to allow classes to be used from the tests directory.
getOption( $name, $default=null)
Get an option, or return the default.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition phpunit.php:93
forceFormatServerArgv()
Force the format of elements in $_SERVER['argv'].
Definition phpunit.php:110
execute()
Do the actual work.
Definition phpunit.php:46
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition phpunit.php:97
__construct()
Default constructor.
Definition phpunit.php:17
finalSetup()
Handle some last-minute setup here.
Definition phpunit.php:37
static applyInitialConfig()
This should be called before Setup.php, e.g.
Definition TestSetup.php:11
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
Definition phpunit.php:128