MediaWiki  1.23.14
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 through this entry point or not
10 define( 'MW_PHPUNIT_TEST', true );
11 
12 // Start up MediaWiki in command-line mode
13 require_once dirname( dirname( __DIR__ ) ) . "/maintenance/Maintenance.php";
14 
16 
17  public function __construct() {
18  parent::__construct();
19  $this->addOption( 'with-phpunitdir',
20  'Directory to include PHPUnit from, for example when using a git fetchout from upstream. Path will be prepended to PHP `include_path`.',
21  false, # not required
22  true # need arg
23  );
24  }
25 
26  public function finalSetup() {
27  parent::finalSetup();
28 
29  global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
30  global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
31  global $wgLocaltimezone, $wgLocalisationCacheConf;
32  global $wgDevelopmentWarnings;
33 
34  // Inject test autoloader
35  require_once __DIR__ . '/../TestsAutoLoader.php';
36 
37  // wfWarn should cause tests to fail
38  $wgDevelopmentWarnings = true;
39 
41  $wgMessageCacheType = CACHE_NONE;
42  $wgParserCacheType = CACHE_NONE;
43  $wgLanguageConverterCacheType = CACHE_NONE;
44 
45  $wgUseDatabaseMessages = false; # Set for future resets
46 
47  // Assume UTC for testing purposes
48  $wgLocaltimezone = 'UTC';
49 
50  $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
51 
52  // Bug 44192 Do not attempt to send a real e-mail
53  Hooks::clear( 'AlternateUserMailer' );
55  'AlternateUserMailer',
56  function () {
57  return false;
58  }
59  );
60  }
61 
62  public function execute() {
63  global $IP;
64 
65  # Make sure we have --configuration or PHPUnit might complain
66  if ( !in_array( '--configuration', $_SERVER['argv'] ) ) {
67  //Hack to eliminate the need to use the Makefile (which sucks ATM)
68  array_splice( $_SERVER['argv'], 1, 0,
69  array( '--configuration', $IP . '/tests/phpunit/suite.xml' ) );
70  }
71 
72  # --with-phpunitdir let us override the default PHPUnit version
73  if ( $this->hasOption( 'with-phpunitdir' ) ) {
74  $phpunitDir = $this->getOption( 'with-phpunitdir' );
75  # Sanity checks
76  if ( !is_dir( $phpunitDir ) ) {
77  $this->error( "--with-phpunitdir should be set to an existing directory", 1 );
78  }
79  if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) {
80  $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 );
81  }
82 
83  # Now prepends provided PHPUnit directory
84  $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" );
85  set_include_path( $phpunitDir . PATH_SEPARATOR . get_include_path() );
86 
87  # Cleanup $args array so the option and its value do not
88  # pollute PHPUnit
89  $key = array_search( '--with-phpunitdir', $_SERVER['argv'] );
90  unset( $_SERVER['argv'][$key] ); // the option
91  unset( $_SERVER['argv'][$key + 1] ); // its value
92  $_SERVER['argv'] = array_values( $_SERVER['argv'] );
93  }
94  }
95 
96  public function getDbType() {
97  return Maintenance::DB_ADMIN;
98  }
99 }
100 
101 $maintClass = 'PHPUnitMaintClass';
103 
104 if ( !class_exists( 'PHPUnit_Runner_Version' ) ) {
105  require_once 'PHPUnit/Runner/Version.php';
106 }
107 
108 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
109  && version_compare( PHPUnit_Runner_Version::id(), '3.7.0', '<' )
110 ) {
111  die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
112 }
113 
114 if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
115  require_once 'PHPUnit/Autoload.php';
116 }
117 
118 // Prevent segfault when we have lots of unit tests (bug 62623)
119 if ( version_compare( PHP_VERSION, '5.4.0', '<' )
120  && version_compare( PHP_VERSION, '5.3.0', '>=' )
121 ) {
122  register_shutdown_function( function() {
123  gc_collect_cycles();
124  gc_disable();
125  } );
126 }
127 
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
CACHE_NONE
const CACHE_NONE
Definition: Defines.php:112
MediaWikiPHPUnitCommand\main
static main( $exit=true)
Definition: MediaWikiPHPUnitCommand.php:40
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
PHPUnitMaintClass\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: phpunit.php:96
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Hooks\clear
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:72
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
PHPUnitMaintClass
Definition: phpunit.php:15
PHPUnitMaintClass\finalSetup
finalSetup()
Handle some last-minute setup here.
Definition: phpunit.php:26
PHPUnitMaintClass\execute
execute()
Do the actual work.
Definition: phpunit.php:62
$maintClass
$maintClass
Definition: phpunit.php:101
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
Maintenance\DB_ADMIN
const DB_ADMIN
Definition: Maintenance.php:59
PHPUnitMaintClass\__construct
__construct()
Default constructor.
Definition: phpunit.php:17
Hooks\register
static register( $name, $callback)
Attach an event handler to a given hook.
Definition: Hooks.php:55
future
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
Definition: distributors.txt:39
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
$wgMainCacheType
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$IP
$IP
Definition: WebStart.php:92