| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
use MediaWiki\HookContainer\HookRunner; |
| 29 |
use MediaWiki\MainConfigSchema; |
| 30 |
use MediaWiki\MediaWikiServices; |
| 31 |
use MediaWiki\Registration\ExtensionProcessor; |
| 32 |
use MediaWiki\Registration\ExtensionRegistry; |
| 33 |
use PHPUnit\TextUI\CliArguments\Builder; |
| 34 |
|
| 35 |
require_once __DIR__ . '/bootstrap.common.php'; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
$envVar = getenv( 'MEDIAWIKI_HAS_INTEGRATION_TESTS' ); |
| 46 |
if ( $envVar !== false ) { |
| 47 |
|
| 48 |
if ( $envVar === 'true' || $envVar === '1' || $envVar === 'yes' ) { |
| 49 |
$hasIntegrationTests = true; |
| 50 |
} elseif ( $envVar === 'false' || $envVar === '0' || $envVar === 'no' ) { |
| 51 |
$hasIntegrationTests = false; |
| 52 |
} else { |
| 53 |
fwrite( STDERR, |
| 54 |
"Unsupported value in MEDIAWIKI_HAS_INTEGRATION_TESTS environment variable,\n" . |
| 55 |
"assuming there are integration tests (but you should fix the environment variable)\n" |
| 56 |
); |
| 57 |
$hasIntegrationTests = true; |
| 58 |
} |
| 59 |
} elseif ( $GLOBALS['argc'] === 1 ) { |
| 60 |
|
| 61 |
|
| 62 |
$hasIntegrationTests = true; |
| 63 |
} else { |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
$paratestArgs = [ 'runner', 'processes', 'passthru-php', 'write-to' ]; |
| 68 |
$phpunitArgs = ( new Builder )->fromParameters( $GLOBALS['argv'], $paratestArgs ); |
| 69 |
if ( $phpunitArgs->hasArgument() ) { |
| 70 |
|
| 71 |
|
| 72 |
$testArgument = strtolower( strtr( $phpunitArgs->argument(), '\\', '/' ) ); |
| 73 |
$hasIntegrationTests = !( str_contains( $testArgument, '/unit/' ) || str_ends_with( $testArgument, '/unit' ) ); |
| 74 |
} elseif ( $phpunitArgs->hasTestSuite() ) { |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
$suites = explode( ',', $phpunitArgs->testSuite() ); |
| 79 |
$unitSuites = [ 'core:unit', 'extensions:unit', 'skins:unit' ]; |
| 80 |
$hasIntegrationTests = array_diff( $suites, $unitSuites ) !== []; |
| 81 |
} else { |
| 82 |
|
| 83 |
$hasIntegrationTests = true; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
if ( !$hasIntegrationTests ) { |
| 88 |
fwrite( STDERR, "Running without MediaWiki settings because there are no integration tests\n" ); |
| 89 |
|
| 90 |
$GLOBALS['wgAutoloadClasses'] = []; |
| 91 |
$GLOBALS['wgBaseDirectory'] = MW_INSTALL_PATH; |
| 92 |
|
| 93 |
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/AutoLoader.php" ); |
| 94 |
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/tests/common/TestsAutoLoader.php" ); |
| 95 |
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/Defines.php" ); |
| 96 |
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/GlobalFunctions.php" ); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) { |
| 101 |
$GLOBALS[$var] = $value; |
| 102 |
} |
| 103 |
|
| 104 |
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/DevelopmentSettings.php" ); |
| 105 |
|
| 106 |
TestSetup::applyInitialConfig(); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
$env = getenv(); |
| 115 |
unset( $env['XDEBUG_CONFIG'] ); |
| 116 |
unset( $env['XDEBUG_MODE'] ); |
| 117 |
unset( $env['XDEBUG_SESSION'] ); |
| 118 |
|
| 119 |
|
| 120 |
$process = proc_open( |
| 121 |
PHP_BINARY . ' ' . __DIR__ . '/getPHPUnitExtensionsAndSkins.php', |
| 122 |
[ |
| 123 |
0 => [ 'pipe', 'r' ], |
| 124 |
1 => [ 'pipe', 'w' ], |
| 125 |
2 => [ 'pipe', 'w' ] |
| 126 |
], |
| 127 |
$pipes, |
| 128 |
null, |
| 129 |
$env |
| 130 |
); |
| 131 |
|
| 132 |
$extensionData = stream_get_contents( $pipes[1] ); |
| 133 |
fclose( $pipes[1] ); |
| 134 |
$cmdErr = stream_get_contents( $pipes[2] ); |
| 135 |
fclose( $pipes[2] ); |
| 136 |
|
| 137 |
$exitCode = proc_close( $process ); |
| 138 |
if ( $exitCode !== 0 ) { |
| 139 |
echo "Cannot load list of extensions and skins. Output:\n$cmdErr\n"; |
| 140 |
exit( 1 ); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
[ $pathsToJsonFilesStr, $testPathsStr ] = explode( "\n\nTESTPATHS\n\n", $extensionData ); |
| 146 |
$pathsToJsonFiles = $pathsToJsonFilesStr ? explode( "\n", $pathsToJsonFilesStr ) : []; |
| 147 |
$testPaths = explode( "\n", $testPathsStr ); |
| 148 |
|
| 149 |
$extensionProcessor = new ExtensionProcessor(); |
| 150 |
foreach ( $pathsToJsonFiles as $filePath ) { |
| 151 |
$extensionProcessor->extractInfoFromFile( $filePath ); |
| 152 |
} |
| 153 |
|
| 154 |
$autoload = $extensionProcessor->getExtractedAutoloadInfo( true ); |
| 155 |
AutoLoader::loadFiles( $autoload['files'] ); |
| 156 |
AutoLoader::registerClasses( $autoload['classes'] ); |
| 157 |
AutoLoader::registerNamespaces( $autoload['namespaces'] ); |
| 158 |
|
| 159 |
|
| 160 |
Profiler::init( [] ); |
| 161 |
} else { |
| 162 |
fwrite( STDERR, "Running with MediaWiki settings because there might be integration tests\n" ); |
| 163 |
TestSetup::loadSettingsFiles(); |
| 164 |
|
| 165 |
$extensionRegistry = ExtensionRegistry::getInstance(); |
| 166 |
$extensionsAndSkins = $extensionRegistry->getQueue(); |
| 167 |
|
| 168 |
$pathsToJsonFiles = array_keys( $extensionsAndSkins ); |
| 169 |
|
| 170 |
$testPaths = []; |
| 171 |
foreach ( $extensionRegistry->getAllThings() as $info ) { |
| 172 |
$testPaths[] = dirname( $info['path'] ) . '/tests/phpunit'; |
| 173 |
} |
| 174 |
|
| 175 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onUnitTestsList( $testPaths ); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
define( 'MW_PHPUNIT_EXTENSIONS_PATHS', array_map( 'dirname', $pathsToJsonFiles ) ); |
| 180 |
|
| 181 |
define( 'MW_PHPUNIT_EXTENSIONS_TEST_PATHS', $testPaths ); |
| 182 |
|
| 183 |
TestSetup::maybeCheckComposerLockUpToDate(); |