MediaWiki REL1_27
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$wgPhpUnitClass = 'PHPUnit_TextUI_Command';
14
15// Start up MediaWiki in command-line mode
16require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
17
19
20 public static $additionalOptions = [
21 'regex' => false,
22 'file' => false,
23 'use-filebackend' => false,
24 'use-bagostuff' => false,
25 'use-jobqueue' => false,
26 'keep-uploads' => false,
27 'use-normal-tables' => false,
28 'reuse-db' => false,
29 'wiki' => false,
30 ];
31
32 public function __construct() {
33 parent::__construct();
34 $this->addOption(
35 'with-phpunitclass',
36 'Class name of the PHPUnit entry point to use',
37 false,
38 true
39 );
40 $this->addOption(
41 'debug-tests',
42 'Log testing activity to the PHPUnitCommand log channel.',
43 false, # not required
44 false # no arg needed
45 );
46 $this->addOption(
47 'regex',
48 'Only run parser tests that match the given regex.',
49 false,
50 true
51 );
52 $this->addOption( 'file', 'File describing parser tests.', false, true );
53 $this->addOption( 'use-filebackend', 'Use filebackend', false, true );
54 $this->addOption( 'use-bagostuff', 'Use bagostuff', false, true );
55 $this->addOption( 'use-jobqueue', 'Use jobqueue', false, true );
56 $this->addOption(
57 'keep-uploads',
58 'Re-use the same upload directory for each test, don\'t delete it.',
59 false,
60 false
61 );
62 $this->addOption( 'use-normal-tables', 'Use normal DB tables.', false, false );
63 $this->addOption(
64 'reuse-db', 'Init DB only if tables are missing and keep after finish.',
65 false,
66 false
67 );
68 }
69
70 public function finalSetup() {
71 parent::finalSetup();
72
81
82 // Inject test autoloader
83 require_once __DIR__ . '/../TestsAutoLoader.php';
84
85 // wfWarn should cause tests to fail
87
88 // Make sure all caches and stashes are either disabled or use
89 // in-process cache only to prevent tests from using any preconfigured
90 // cache meant for the local wiki from outside the test run.
91 // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
92
93 // Disabled in DefaultSettings, override local settings
96 // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
101 // Uses db-replicated in DefaultSettings
102 $wgMainStash = 'hash';
103 // Use memory job queue
105 'default' => [ 'class' => 'JobQueueMemory', 'order' => 'fifo' ],
106 ];
107
108 $wgUseDatabaseMessages = false; # Set for future resets
109
110 // Assume UTC for testing purposes
111 $wgLocaltimezone = 'UTC';
112
113 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
114
115 // Generic MediaWiki\Session\SessionManager configuration for tests
116 // We use CookieSessionProvider because things might be expecting
117 // cookies to show up in a FauxRequest somewhere.
119 [
120 'class' => MediaWiki\Session\CookieSessionProvider::class,
121 'args' => [ [
122 'priority' => 30,
123 'callUserSetCookiesHook' => true,
124 ] ],
125 ],
126 ];
127
128 // Generic AuthManager configuration for testing
130 'preauth' => [],
131 'primaryauth' => [
132 [
133 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class,
134 'args' => [ [
135 'authoritative' => false,
136 ] ],
137 ],
138 [
139 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class,
140 'args' => [ [
141 'authoritative' => true,
142 ] ],
143 ],
144 ],
145 'secondaryauth' => [],
146 ];
148
149 // Bug 44192 Do not attempt to send a real e-mail
150 Hooks::clear( 'AlternateUserMailer' );
151 Hooks::register(
152 'AlternateUserMailer',
153 function () {
154 return false;
155 }
156 );
157 // xdebug's default of 100 is too low for MediaWiki
158 ini_set( 'xdebug.max_nesting_level', 1000 );
159
160 // Bug T116683 serialize_precision of 100
161 // may break testing against floating point values
162 // treated with PHP's serialize()
163 ini_set( 'serialize_precision', 17 );
164 }
165
166 public function execute() {
167 global $IP;
168
169 // Deregister handler from MWExceptionHandler::installHandle so that PHPUnit's own handler
170 // stays in tact.
171 // Has to in execute() instead of finalSetup(), because finalSetup() runs before
172 // doMaintenance.php includes Setup.php, which calls MWExceptionHandler::installHandle().
173 restore_error_handler();
174
175 $this->forceFormatServerArgv();
176
177 # Make sure we have --configuration or PHPUnit might complain
178 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
179 // Hack to eliminate the need to use the Makefile (which sucks ATM)
180 array_splice( $_SERVER['argv'], 1, 0,
181 [ '--configuration', $IP . '/tests/phpunit/suite.xml' ] );
182 }
183
184 if ( $this->hasOption( 'with-phpunitclass' ) ) {
186 $wgPhpUnitClass = $this->getOption( 'with-phpunitclass' );
187
188 # Cleanup $args array so the option and its value do not
189 # pollute PHPUnit
190 $key = array_search( '--with-phpunitclass', $_SERVER['argv'] );
191 unset( $_SERVER['argv'][$key] ); // the option
192 unset( $_SERVER['argv'][$key + 1] ); // its value
193 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
194 }
195
196 $key = array_search( '--debug-tests', $_SERVER['argv'] );
197 if ( $key !== false && array_search( '--printer', $_SERVER['argv'] ) === false ) {
198 unset( $_SERVER['argv'][$key] );
199 array_splice( $_SERVER['argv'], 1, 0, 'MediaWikiPHPUnitTestListener' );
200 array_splice( $_SERVER['argv'], 1, 0, '--printer' );
201 }
202
203 foreach ( self::$additionalOptions as $option => $default ) {
204 $key = array_search( '--' . $option, $_SERVER['argv'] );
205 if ( $key !== false ) {
206 unset( $_SERVER['argv'][$key] );
207 if ( $this->mParams[$option]['withArg'] ) {
208 self::$additionalOptions[$option] = $_SERVER['argv'][$key + 1];
209 unset( $_SERVER['argv'][$key + 1] );
210 } else {
211 self::$additionalOptions[$option] = true;
212 }
213 }
214 }
215
216 }
217
218 public function getDbType() {
220 }
221
226 private function forceFormatServerArgv() {
227 $argv = [];
228 foreach ( $_SERVER['argv'] as $key => $arg ) {
229 if ( $key === 0 ) {
230 $argv[0] = $arg;
231 } elseif ( strstr( $arg, '=' ) ) {
232 foreach ( explode( '=', $arg, 2 ) as $argPart ) {
233 $argv[] = $argPart;
234 }
235 } else {
236 $argv[] = $arg;
237 }
238 }
239 $_SERVER['argv'] = $argv;
240 }
241
242}
243
244$maintClass = 'PHPUnitMaintClass';
246
247if ( !class_exists( 'PHPUnit_Framework_TestCase' ) ) {
248 echo "PHPUnit not found. Please install it and other dev dependencies by
249running `composer install` in MediaWiki root directory.\n";
250 exit( 1 );
251}
252if ( !class_exists( $wgPhpUnitClass ) ) {
253 echo "PHPUnit entry point '" . $wgPhpUnitClass . "' not found. Please make sure you installed
254the containing component and check the spelling of the class name.\n";
255 exit( 1 );
256}
257
258echo defined( 'HHVM_VERSION' ) ?
259 'Using HHVM ' . HHVM_VERSION . ' (' . PHP_VERSION . ")\n" :
260 'Using PHP ' . PHP_VERSION . "\n";
261
262$wgPhpUnitClass::main();
$wgJobTypeConf
Map of job types to configuration arrays.
$wgParserCacheType
The cache type for storing article HTML.
$wgSessionProviders
MediaWiki\Session\SessionProvider configuration.
$wgAuthManagerConfig
Configure AuthManager.
$wgUseDatabaseMessages
Translation using MediaWiki: namespace.
$wgMessageCacheType
The cache type for storing the contents of the MediaWiki namespace.
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
$wgAuth $wgAuth
Authentication plugin.
$wgMainStash
Main object stash type.
$wgSessionCacheType
The cache type for storing session data.
$wgLanguageConverterCacheType
The cache type for storing language conversion tables, which are used when parsing certain text and i...
$wgDevelopmentWarnings
If set to true MediaWiki will throw notices for some possible error conditions and for deprecated fun...
$wgMainWANCache
Main Wide-Area-Network cache type.
$wgLocalisationCacheConf
Localisation cache configuration.
$IP
Definition WebStart.php:58
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular param exists.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Backwards-compatibility wrapper for AuthManager via $wgAuth.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition phpunit.php:218
forceFormatServerArgv()
Force the format of elements in $_SERVER['argv'].
Definition phpunit.php:226
execute()
Do the actual work.
Definition phpunit.php:166
static $additionalOptions
Definition phpunit.php:20
__construct()
Default constructor.
Definition phpunit.php:32
finalSetup()
Handle some last-minute setup here.
Definition phpunit.php:70
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when needed(most notably, OutputPage::addWikiText()). The StandardSkin object is a complete implementation
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the future
const CACHE_NONE
Definition Defines.php:103
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN
CACHE_MEMCACHED $wgMainCacheType
Definition memcached.txt:63
$maintClass
Definition phpunit.php:244
$wgPhpUnitClass
Definition phpunit.php:13