Pass phpcs-strict on some test files (11/11)
[lhc/web/wiklou.git] / tests / phpunit / phpunit.php
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Bootstrapping for MediaWiki PHPUnit tests
5 *
6 * @file
7 */
8
9 // Set a flag which can be used to detect when other scripts have been entered
10 // through this entry point or not.
11 define( 'MW_PHPUNIT_TEST', true );
12
13 // Start up MediaWiki in command-line mode
14 require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
15
16 class PHPUnitMaintClass extends Maintenance {
17
18 public function __construct() {
19 parent::__construct();
20 $this->addOption(
21 'with-phpunitdir',
22 'Directory to include PHPUnit from, for example when using a git '
23 . 'fetchout from upstream. Path will be prepended to PHP `include_path`.',
24 false, # not required
25 true # need arg
26 );
27 }
28
29 public function finalSetup() {
30 parent::finalSetup();
31
32 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
33 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
34 global $wgLocaltimezone, $wgLocalisationCacheConf;
35 global $wgDevelopmentWarnings;
36
37 // Inject test autoloader
38 require_once __DIR__ . '/../TestsAutoLoader.php';
39
40 // wfWarn should cause tests to fail
41 $wgDevelopmentWarnings = true;
42
43 $wgMainCacheType = CACHE_NONE;
44 $wgMessageCacheType = CACHE_NONE;
45 $wgParserCacheType = CACHE_NONE;
46 $wgLanguageConverterCacheType = CACHE_NONE;
47
48 $wgUseDatabaseMessages = false; # Set for future resets
49
50 // Assume UTC for testing purposes
51 $wgLocaltimezone = 'UTC';
52
53 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
54
55 // Bug 44192 Do not attempt to send a real e-mail
56 Hooks::clear( 'AlternateUserMailer' );
57 Hooks::register(
58 'AlternateUserMailer',
59 function () {
60 return false;
61 }
62 );
63 }
64
65 public function execute() {
66 global $IP;
67
68 # Make sure we have --configuration or PHPUnit might complain
69 if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
70 //Hack to eliminate the need to use the Makefile (which sucks ATM)
71 array_splice( $_SERVER['argv'], 1, 0,
72 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
73 }
74
75 # --with-phpunitdir let us override the default PHPUnit version
76 if ( $this->hasOption( 'with-phpunitdir' ) ) {
77 $phpunitDir = $this->getOption( 'with-phpunitdir' );
78 # Sanity checks
79 if ( !is_dir( $phpunitDir ) ) {
80 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
81 }
82 if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
83 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
84 }
85
86 # Now prepends provided PHPUnit directory
87 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
88 set_include_path( $phpunitDir . PATH_SEPARATOR . get_include_path() );
89
90 # Cleanup $args array so the option and its value do not
91 # pollute PHPUnit
92 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
93 unset( $_SERVER['argv'][$key] ); // the option
94 unset( $_SERVER['argv'][$key + 1] ); // its value
95 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
96 }
97 }
98
99 public function getDbType() {
100 return Maintenance::DB_ADMIN;
101 }
102 }
103
104 $maintClass = 'PHPUnitMaintClass';
105 require RUN_MAINTENANCE_IF_MAIN;
106
107 if ( !class_exists( 'PHPUnit_Runner_Version' ) ) {
108 require_once 'PHPUnit/Runner/Version.php';
109 }
110
111 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
112 && version_compare( PHPUnit_Runner_Version::id(), '3.7.0', '<' )
113 ) {
114 die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
115 }
116
117 if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
118 require_once 'PHPUnit/Autoload.php';
119 }
120
121 // Prevent segfault when we have lots of unit tests (bug 62623)
122 if ( version_compare( PHP_VERSION, '5.4.0', '<' )
123 && version_compare( PHP_VERSION, '5.3.0', '>=' )
124 ) {
125 register_shutdown_function( function() {
126 gc_collect_cycles();
127 gc_disable();
128 } );
129 }
130
131 MediaWikiPHPUnitCommand::main();