2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
2019-06-26 02:33:14 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
/**
|
2019-06-26 02:33:14 +00:00
|
|
|
* 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
|
2010-12-14 16:26:35 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2019-06-26 02:33:14 +00:00
|
|
|
* @ingroup Testing
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-21 16:28:35 +00:00
|
|
|
use MediaWiki\MainConfigSchema;
|
|
|
|
|
|
2023-07-08 13:27:52 +00:00
|
|
|
require_once __DIR__ . '/bootstrap.common.php';
|
2019-06-26 02:33:14 +00:00
|
|
|
|
2022-04-24 12:36:10 +00:00
|
|
|
/** @internal Should only be used in MediaWikiIntegrationTestCase::initializeForStandardPhpunitEntrypointIfNeeded() */
|
|
|
|
|
define( 'MW_PHPUNIT_UNIT', true );
|
|
|
|
|
|
phpunit: Repair GLOBALS reset in MediaWikiUnitTestCase
This code didn't work because the $GLOBALS array is exposed by reference.
Once this reference was broken by unset(), the rest just manipulated a
local array that happens to be called "GLOBALS". It must not be unset or
re-assigned. It can only be changed in-place.
Before this, the execution of a MediaWikiUnitTestCase test stored a
copy of GLOBALS in unitGlobals, then lost the GLOBALS pointer and
created a new variable called "GLOBALS". As such, the tearDown() function
didn't do what it meant to do, either – which then results in odd
failures like T230023
Rewrite it as follows:
* In setup, store the current GLOBALS keys and values, then reduce
GLOBALS to only the whitelisted keys and values.
* In teardown, restore the original state.
* As optimisation, do this from setUpBeforeClass as well, so that
there are relatively few globals to reset between tests.
(Thanks @Simetrical!)
The following tests were previously passing by accident under
MediaWikiUnitTestCase but actually did depend on global config.
* MainSlotRoleHandlerTest (…, ContentHandler, $wgContentHandlers)
* SlotRecordTest (…, ContentHandler, $wgContentHandlers)
* WikiReferenceTest (wfParseUrl, $wgUrlProtocols)
* DifferenceEngineSlotDiffRendererTest (DifferenceEngine, wfDebug, …)
* SlotDiffRendererTest (…, ContentHandler, $wgContentHandlers)
* FileBackendDBRepoWrapperTest (wfWikiID, "Backend domain ID not provided")
* JpegMetadataExtractorTest (…, wfDebug, …, LoggerFactory, …)
* ParserFactoryTest (…, wfDebug, …, LoggerFactory, InvalidArgumentException)
* MediaWikiPageNameNormalizerTest (…, wfDebug, …, LoggerFactory, …)
* SiteExporterTest (SiteImporter, wfLogWarning, …)
* SiteImporterTest (Site::newForType, $wgSiteTypes)
* ZipDirectoryReaderTest (…, wfDebug, …, LoggerFactory, …)
Bug: T230023
Change-Id: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7
2019-08-07 13:40:55 +00:00
|
|
|
// Faking in lieu of Setup.php
|
2019-06-26 02:33:14 +00:00
|
|
|
$GLOBALS['wgAutoloadClasses'] = [];
|
2022-02-21 16:28:35 +00:00
|
|
|
$GLOBALS['wgBaseDirectory'] = MW_INSTALL_PATH;
|
2019-06-26 02:33:14 +00:00
|
|
|
|
2023-07-13 00:01:29 +00:00
|
|
|
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/AutoLoader.php" );
|
|
|
|
|
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/tests/common/TestsAutoLoader.php" );
|
|
|
|
|
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/Defines.php" );
|
|
|
|
|
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/GlobalFunctions.php" );
|
2019-07-01 19:33:54 +00:00
|
|
|
|
2022-02-21 16:28:35 +00:00
|
|
|
// Extract the defaults into global variables.
|
|
|
|
|
// NOTE: this does not apply any dynamic defaults.
|
|
|
|
|
foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) {
|
|
|
|
|
$GLOBALS[$var] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 00:01:29 +00:00
|
|
|
TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/DevelopmentSettings.php" );
|
2022-02-21 16:28:35 +00:00
|
|
|
|
2020-04-21 05:47:54 +00:00
|
|
|
TestSetup::applyInitialConfig();
|
|
|
|
|
|
2022-01-28 19:17:51 +00:00
|
|
|
// Since we do not load settings, expect to find extensions and skins
|
|
|
|
|
// in their respective default locations.
|
2023-07-13 00:01:29 +00:00
|
|
|
$GLOBALS['wgExtensionDirectory'] = MW_INSTALL_PATH . "/extensions";
|
|
|
|
|
$GLOBALS['wgStyleDirectory'] = MW_INSTALL_PATH . "/skins";
|
2022-01-28 19:17:51 +00:00
|
|
|
|
2019-08-19 08:16:06 +00:00
|
|
|
// Populate classes and namespaces from extensions and skins present in filesystem.
|
2019-07-01 19:33:54 +00:00
|
|
|
$directoryToJsonMap = [
|
2020-08-07 15:45:33 +00:00
|
|
|
$GLOBALS['wgExtensionDirectory'] => 'extension*.json',
|
|
|
|
|
$GLOBALS['wgStyleDirectory'] => 'skin*.json'
|
2019-07-01 19:33:54 +00:00
|
|
|
];
|
2022-03-24 14:18:07 +00:00
|
|
|
|
|
|
|
|
$extensionProcessor = new ExtensionProcessor();
|
|
|
|
|
|
2020-08-07 15:45:33 +00:00
|
|
|
foreach ( $directoryToJsonMap as $directory => $jsonFilePattern ) {
|
|
|
|
|
foreach ( new GlobIterator( $directory . '/*/' . $jsonFilePattern ) as $iterator ) {
|
|
|
|
|
$jsonPath = $iterator->getPathname();
|
2022-03-24 14:18:07 +00:00
|
|
|
$extensionProcessor->extractInfoFromFile( $jsonPath );
|
2019-07-01 19:33:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-24 14:18:07 +00:00
|
|
|
|
|
|
|
|
$autoload = $extensionProcessor->getExtractedAutoloadInfo( true );
|
|
|
|
|
AutoLoader::loadFiles( $autoload['files'] );
|
|
|
|
|
AutoLoader::registerClasses( $autoload['classes'] );
|
|
|
|
|
AutoLoader::registerNamespaces( $autoload['namespaces'] );
|
2022-06-28 01:39:08 +00:00
|
|
|
|
|
|
|
|
// More faking in lieu of Setup.php
|
|
|
|
|
Profiler::init( [] );
|
2023-02-24 09:54:49 +00:00
|
|
|
|
2023-07-10 21:50:22 +00:00
|
|
|
TestSetup::maybeCheckComposerLockUpToDate();
|