wfWarn() should cause phpunit tests to fail.
[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 global $wgDevelopmentWarnings;
38
39 // wfWarn should cause tests to fail
40 $wgDevelopmentWarnings = true;
41
42 $wgMainCacheType = CACHE_NONE;
43 $wgMessageCacheType = CACHE_NONE;
44 $wgParserCacheType = CACHE_NONE;
45 $wgLanguageConverterCacheType = CACHE_NONE;
46
47 $wgUseDatabaseMessages = false; # Set for future resets
48
49 // Assume UTC for testing purposes
50 $wgLocaltimezone = 'UTC';
51
52 $wgLocalisationCacheConf['storeClass'] = 'LCStore_Null';
53 }
54
55 public function execute() {
56 global $IP;
57
58 # Make sure we have --configuration or PHPUnit might complain
59 if( !in_array( '--configuration', $_SERVER['argv'] ) ) {
60 //Hack to eliminate the need to use the Makefile (which sucks ATM)
61 array_splice( $_SERVER['argv'], 1, 0,
62 array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
63 }
64
65 # --with-phpunitdir let us override the default PHPUnit version
66 if( $phpunitDir = $this->getOption( 'with-phpunitdir' ) ) {
67 # Sanity checks
68 if( !is_dir($phpunitDir) ) {
69 $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
70 }
71 if( !is_readable( $phpunitDir."/PHPUnit/Runner/Version.php" ) ) {
72 $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
73 }
74
75 # Now prepends provided PHPUnit directory
76 $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
77 set_include_path( $phpunitDir
78 . PATH_SEPARATOR . get_include_path() );
79
80 # Cleanup $args array so the option and its value do not
81 # pollute PHPUnit
82 $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
83 unset( $_SERVER['argv'][$key] ); // the option
84 unset( $_SERVER['argv'][$key+1] ); // its value
85 $_SERVER['argv'] = array_values( $_SERVER['argv'] );
86
87 }
88 }
89
90 public function getDbType() {
91 return Maintenance::DB_ADMIN;
92 }
93 }
94
95 $maintClass = 'PHPUnitMaintClass';
96 require( RUN_MAINTENANCE_IF_MAIN );
97
98 require_once( 'PHPUnit/Runner/Version.php' );
99
100 if( PHPUnit_Runner_Version::id() !== '@package_version@'
101 && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' ) ) {
102 die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
103 }
104 require_once( 'PHPUnit/Autoload.php' );
105
106 require_once( "$IP/tests/TestsAutoLoader.php" );
107 MediaWikiPHPUnitCommand::main();