Merge "Do proper conversion table detection."
[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 /* Configuration */
10
11 // Evaluate the include path relative to this file
12 $IP = dirname( dirname( dirname( __FILE__ ) ) );
13
14 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not
15 define( 'MW_PHPUNIT_TEST', true );
16
17 // Start up MediaWiki in command-line mode
18 require_once( "$IP/maintenance/Maintenance.php" );
19
20 class PHPUnitMaintClass extends Maintenance {
21
22 function __construct() {
23 parent::__construct();
24 $this->addOption( 'with-phpunitdir'
25 , 'Directory to include PHPUnit from, for example when using a git fetchout from upstream. Path will be prepended to PHP `include_path`.'
26 , false # not required
27 , true # need arg
28 );
29 }
30
31 public function finalSetup() {
32 parent::finalSetup();
33
34 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
35 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
36 global $wgLocaltimezone, $wgLocalisationCacheConf;
37
38 $wgMainCacheType = CACHE_NONE;
39 $wgMessageCacheType = CACHE_NONE;
40 $wgParserCacheType = CACHE_NONE;
41 $wgLanguageConverterCacheType = CACHE_NONE;
42
43 $wgUseDatabaseMessages = false; # Set for future resets
44
45 // Assume UTC for testing purposes
46 $wgLocaltimezone = 'UTC';
47
48 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null';
49 }
50
51 public function execute() {
52 global $IP;
53
54 # Make sure we have --configuration or PHPUnit might complain
55 if( !in_array( '--configuration', $_SERVER['argv'] ) ) {
56 //Hack to eliminate the need to use the Makefile (which sucks ATM)
57 array_splice( $_SERVER['argv'], 1, 0,
58 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
59 }
60
61 # --with-phpunitdir let us override the default PHPUnit version
62 if( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
63 # Sanity checks
64 if( !is_dir($phpunitDir) ) {
65 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
66 }
67 if( !is_readable( $phpunitDir."/PHPUnit/Runner/Version.php" ) ) {
68 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
69 }
70
71 # Now prepends provided PHPUnit directory
72 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
73 set_include_path( $phpunitDir
74 . PATH_SEPARATOR . get_include_path() );
75
76 # Cleanup $args array so the option and its value do not
77 # pollute PHPUnit
78 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
79 unset( $_SERVER['argv'][$key] ); // the option
80 unset( $_SERVER['argv'][$key+1] ); // its value
81 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
82
83 }
84 }
85
86 public function getDbType() {
87 return Maintenance::DB_ADMIN;
88 }
89 }
90
91 $maintClass = 'PHPUnitMaintClass';
92 require( RUN_MAINTENANCE_IF_MAIN );
93
94 require_once( 'PHPUnit/Runner/Version.php' );
95
96 if( PHPUnit_Runner_Version::id() !== '@package_version@'
97 && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' ) ) {
98 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
99 }
100 require_once( 'PHPUnit/Autoload.php' );
101
102 require_once( "$IP/tests/TestsAutoLoader.php" );
103 MediaWikiPHPUnitCommand::main();