| 1 |
#!/usr/bin/env php |
| 2 |
<?php |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
use MediaWiki\MediaWikiServices; |
| 10 |
use MediaWiki\Registration\ExtensionRegistry; |
| 11 |
use PHPUnit\TextUI\Command; |
| 12 |
|
| 13 |
class PHPUnitMaintClass { |
| 14 |
public function setup() { |
| 15 |
|
| 16 |
|
| 17 |
define( 'MW_PHPUNIT_TEST', true ); |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
if ( ini_get( 'display_errors' ) ) { |
| 23 |
ini_set( 'display_errors', 'stderr' ); |
| 24 |
} |
| 25 |
|
| 26 |
$this->prepareEnvironment(); |
| 27 |
require_once __DIR__ . '/../common/TestSetup.php'; |
| 28 |
TestSetup::snapshotGlobals(); |
| 29 |
} |
| 30 |
|
| 31 |
public function prepareEnvironment() { |
| 32 |
|
| 33 |
ini_set( 'memory_limit', -1 ); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
ini_set( 'max_execution_time', 0 ); |
| 39 |
|
| 40 |
|
| 41 |
while ( ob_get_level() > 0 ) { |
| 42 |
ob_end_flush(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public function finalSetup() { |
| 47 |
global $wgDBadminuser, $wgDBadminpassword; |
| 48 |
global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf; |
| 49 |
|
| 50 |
|
| 51 |
$this->prepareEnvironment(); |
| 52 |
|
| 53 |
if ( isset( $wgDBadminuser ) ) { |
| 54 |
$wgDBuser = $wgDBadminuser; |
| 55 |
$wgDBpassword = $wgDBadminpassword; |
| 56 |
|
| 57 |
if ( $wgDBservers ) { |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
foreach ( $wgDBservers as $i => $server ) { |
| 62 |
$wgDBservers[$i]['user'] = $wgDBuser; |
| 63 |
$wgDBservers[$i]['password'] = $wgDBpassword; |
| 64 |
} |
| 65 |
} |
| 66 |
if ( isset( $wgLBFactoryConf['serverTemplate'] ) ) { |
| 67 |
$wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser; |
| 68 |
$wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword; |
| 69 |
} |
| 70 |
$service = MediaWikiServices::getInstance()->peekService( 'DBLoadBalancerFactory' ); |
| 71 |
if ( $service ) { |
| 72 |
$service->destroy(); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
require_once __DIR__ . '/../common/TestsAutoLoader.php'; |
| 77 |
|
| 78 |
TestSetup::applyInitialConfig(); |
| 79 |
|
| 80 |
ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces( true ); |
| 81 |
} |
| 82 |
|
| 83 |
public function execute() { |
| 84 |
|
| 85 |
|
| 86 |
ob_start(); |
| 87 |
|
| 88 |
fwrite( STDERR, 'Using PHP ' . PHP_VERSION . "\n" ); |
| 89 |
|
| 90 |
$command = new Command(); |
| 91 |
$args = $_SERVER['argv']; |
| 92 |
$knownOpts = getopt( 'c:', [ 'configuration:', 'bootstrap:' ] ) ?: []; |
| 93 |
if ( !isset( $knownOpts['c'] ) && !isset( $knownOpts['configuration'] ) ) { |
| 94 |
|
| 95 |
|
| 96 |
$args[] = '--configuration=' . __DIR__ . '/suite.xml'; |
| 97 |
} |
| 98 |
if ( !isset( $knownOpts['bootstrap'] ) ) { |
| 99 |
$args[] = '--bootstrap=' . __DIR__ . '/bootstrap.maintenance.php'; |
| 100 |
} |
| 101 |
$command->run( $args, true ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
$deprecationMsg = <<<EOT |
| 106 |
******************************************************************************* |
| 107 |
DEPRECATED: The tests/phpunit/phpunit.php entry point has been deprecated. Use |
| 108 |
`composer phpunit` instead. |
| 109 |
******************************************************************************* |
| 110 |
|
| 111 |
EOT; |
| 112 |
|
| 113 |
fwrite( STDERR, $deprecationMsg ); |
| 114 |
|
| 115 |
if ( defined( 'MEDIAWIKI' ) ) { |
| 116 |
exit( 'Wrong entry point?' ); |
| 117 |
} |
| 118 |
|
| 119 |
if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) { |
| 120 |
exit( 'This script must be run from the command line' ); |
| 121 |
} |
| 122 |
|
| 123 |
define( 'MW_ENTRY_POINT', 'cli' ); |
| 124 |
|
| 125 |
if ( strval( getenv( 'MW_INSTALL_PATH' ) ) === '' ) { |
| 126 |
putenv( 'MW_INSTALL_PATH=' . realpath( __DIR__ . '/../..' ) ); |
| 127 |
} |
| 128 |
|
| 129 |
if ( getenv( 'PHPUNIT_WIKI' ) ) { |
| 130 |
$wikiName = getenv( 'PHPUNIT_WIKI' ); |
| 131 |
$bits = explode( '-', $wikiName, 2 ); |
| 132 |
define( 'MW_DB', $bits[0] ); |
| 133 |
define( 'MW_PREFIX', $bits[1] ?? '' ); |
| 134 |
define( 'MW_WIKI_NAME', $wikiName ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
define( 'MEDIAWIKI', true ); |
| 139 |
|
| 140 |
define( 'PHPUNIT_LEGACY_ENTRYPOINT', true ); |
| 141 |
|
| 142 |
$IP = getenv( 'MW_INSTALL_PATH' ); |
| 143 |
|
| 144 |
$wrapper = new PHPUnitMaintClass(); |
| 145 |
$wrapper->setup(); |
| 146 |
|
| 147 |
require_once "$IP/includes/BootstrapHelperFunctions.php"; |
| 148 |
|
| 149 |
$IP = wfDetectInstallPath(); |
| 150 |
wfDetectLocalSettingsFile( $IP ); |
| 151 |
|
| 152 |
function wfPHPUnitSetup() { |
| 153 |
|
| 154 |
global $wrapper; |
| 155 |
$wrapper->finalSetup(); |
| 156 |
} |
| 157 |
|
| 158 |
define( 'MW_SETUP_CALLBACK', 'wfPHPUnitSetup' ); |
| 159 |
|
| 160 |
require_once "$IP/includes/Setup.php"; |
| 161 |
|
| 162 |
|
| 163 |
restore_error_handler(); |
| 164 |
|
| 165 |
|
| 166 |
if ( !getenv( 'MW_SKIP_EXTERNAL_DEPENDENCIES' ) ) { |
| 167 |
$composerLockUpToDate = new CheckComposerLockUpToDate(); |
| 168 |
$composerLockUpToDate->loadParamsAndArgs( 'phpunit', [ 'quiet' => true ] ); |
| 169 |
$composerLockUpToDate->execute(); |
| 170 |
} |
| 171 |
|
| 172 |
$wrapper->execute(); |