This change cleans up when and how we register autoloader info for extensions. This bumps CACHE_VERSION to 8, to avoid issues in case this patch gets reverted: the new code doesn't copy the map of class files into $info['globals']['AutoloadClasses']. If old code was to read a new cache entry, autoloading would fail. BREAKING CHANGE: The following methods have been removed from ExtensionRegistry without deprecation and without replacement. They had been introduced in 1.35 for use in the testing framework, and were not in use by any known extension: - exportAutoloadClassesAndNamespaces - exportTestAutoloadClassesAndNamespaces NOTE: breaks the hack that SocialProfile has in place for T243861. Bug: T240535 Change-Id: I6e1ceac034c443d9475f1adc1babecddd6af6d05
96 lines
3.4 KiB
PHP
96 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* PHPUnit bootstrap file.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
* @ingroup Testing
|
|
*/
|
|
|
|
use MediaWiki\MainConfigSchema;
|
|
|
|
if ( PHP_SAPI !== 'cli' ) {
|
|
die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
|
|
}
|
|
|
|
define( 'MEDIAWIKI', true );
|
|
define( 'MW_PHPUNIT_TEST', true );
|
|
define( 'MW_ENTRY_POINT', 'cli' );
|
|
|
|
/** @internal Should only be used in MediaWikiIntegrationTestCase::initializeForStandardPhpunitEntrypointIfNeeded() */
|
|
define( 'MW_PHPUNIT_UNIT', true );
|
|
|
|
$IP = realpath( __DIR__ . '/../../' );
|
|
require_once "$IP/tests/common/TestSetup.php";
|
|
|
|
// We don't use a settings file here but some code still assumes that one exists
|
|
TestSetup::requireOnceInGlobalScope( "$IP/includes/BootstrapHelperFunctions.php" );
|
|
|
|
$IP = wfDetectInstallPath(); // ensure MW_INSTALL_PATH is defined
|
|
wfDetectLocalSettingsFile( $IP );
|
|
|
|
// these variables must be defined before setup runs
|
|
$GLOBALS['IP'] = $IP;
|
|
|
|
TestSetup::snapshotGlobals();
|
|
|
|
// Faking in lieu of Setup.php
|
|
$GLOBALS['wgCommandLineMode'] = true;
|
|
$GLOBALS['wgAutoloadClasses'] = [];
|
|
$GLOBALS['wgBaseDirectory'] = MW_INSTALL_PATH;
|
|
|
|
TestSetup::requireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
|
|
TestSetup::requireOnceInGlobalScope( "$IP/tests/common/TestsAutoLoader.php" );
|
|
TestSetup::requireOnceInGlobalScope( "$IP/includes/Defines.php" );
|
|
TestSetup::requireOnceInGlobalScope( "$IP/includes/GlobalFunctions.php" );
|
|
|
|
// Extract the defaults into global variables.
|
|
// NOTE: this does not apply any dynamic defaults.
|
|
foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) {
|
|
$GLOBALS[$var] = $value;
|
|
}
|
|
|
|
TestSetup::requireOnceInGlobalScope( "$IP/includes/DevelopmentSettings.php" );
|
|
|
|
TestSetup::applyInitialConfig();
|
|
MediaWikiCliOptions::initialize();
|
|
|
|
// Since we do not load settings, expect to find extensions and skins
|
|
// in their respective default locations.
|
|
$GLOBALS['wgExtensionDirectory'] = "$IP/extensions";
|
|
$GLOBALS['wgStyleDirectory'] = "$IP/skins";
|
|
|
|
// Populate classes and namespaces from extensions and skins present in filesystem.
|
|
$directoryToJsonMap = [
|
|
$GLOBALS['wgExtensionDirectory'] => 'extension*.json',
|
|
$GLOBALS['wgStyleDirectory'] => 'skin*.json'
|
|
];
|
|
|
|
$extensionProcessor = new ExtensionProcessor();
|
|
|
|
foreach ( $directoryToJsonMap as $directory => $jsonFilePattern ) {
|
|
foreach ( new GlobIterator( $directory . '/*/' . $jsonFilePattern ) as $iterator ) {
|
|
$jsonPath = $iterator->getPathname();
|
|
$extensionProcessor->extractInfoFromFile( $jsonPath );
|
|
}
|
|
}
|
|
|
|
$autoload = $extensionProcessor->getExtractedAutoloadInfo( true );
|
|
AutoLoader::loadFiles( $autoload['files'] );
|
|
AutoLoader::registerClasses( $autoload['classes'] );
|
|
AutoLoader::registerNamespaces( $autoload['namespaces'] );
|