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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if ( PHP_SAPI !== 'cli' ) {
|
|
|
|
|
die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PHPUnit includes the bootstrap file inside a method body, while most MediaWiki startup files
|
|
|
|
|
* assume to be included in the global scope.
|
|
|
|
|
* This utility provides a way to include these files: it makes all globals available in the
|
|
|
|
|
* inclusion scope before including the file, then exports all new or changed globals.
|
|
|
|
|
*
|
|
|
|
|
* @param string $fileName the file to include
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2019-06-26 02:33:14 +00:00
|
|
|
function wfRequireOnceInGlobalScope( $fileName ) {
|
|
|
|
|
// phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
|
|
|
|
|
extract( $GLOBALS, EXTR_REFS | EXTR_SKIP );
|
|
|
|
|
// phpcs:enable
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2019-06-26 02:33:14 +00:00
|
|
|
require_once $fileName;
|
|
|
|
|
|
|
|
|
|
foreach ( get_defined_vars() as $varName => $value ) {
|
|
|
|
|
$GLOBALS[$varName] = $value;
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2014-05-05 12:43:00 +00:00
|
|
|
|
2019-06-26 02:33:14 +00:00
|
|
|
define( 'MEDIAWIKI', true );
|
|
|
|
|
define( 'MW_PHPUNIT_TEST', true );
|
2020-03-31 22:27:02 +00:00
|
|
|
define( 'MW_ENTRY_POINT', 'cli' );
|
2019-06-26 02:33:14 +00:00
|
|
|
|
|
|
|
|
$IP = realpath( __DIR__ . '/../../' );
|
2019-08-14 08:25:01 +00:00
|
|
|
// We don't use a settings file here but some code still assumes that one exists
|
|
|
|
|
define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
|
2019-06-26 02:33:14 +00:00
|
|
|
|
|
|
|
|
// these variables must be defined before setup runs
|
|
|
|
|
$GLOBALS['IP'] = $IP;
|
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
|
|
|
|
|
|
|
|
require_once "$IP/tests/common/TestSetup.php";
|
|
|
|
|
TestSetup::snapshotGlobals();
|
|
|
|
|
|
|
|
|
|
// Faking in lieu of Setup.php
|
2019-06-26 02:33:14 +00:00
|
|
|
$GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test';
|
|
|
|
|
$GLOBALS['wgCommandLineMode'] = true;
|
|
|
|
|
$GLOBALS['wgAutoloadClasses'] = [];
|
|
|
|
|
|
|
|
|
|
wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
|
|
|
|
|
wfRequireOnceInGlobalScope( "$IP/tests/common/TestsAutoLoader.php" );
|
2019-06-30 13:23:53 +00:00
|
|
|
wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
|
2019-07-01 19:33:54 +00:00
|
|
|
wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
|
2019-07-13 20:50:28 +00:00
|
|
|
wfRequireOnceInGlobalScope( "$IP/includes/GlobalFunctions.php" );
|
2019-07-01 19:33:54 +00:00
|
|
|
|
2020-04-21 05:47:54 +00:00
|
|
|
TestSetup::applyInitialConfig();
|
|
|
|
|
|
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
|
|
|
];
|
2020-08-07 15:45:33 +00:00
|
|
|
foreach ( $directoryToJsonMap as $directory => $jsonFilePattern ) {
|
|
|
|
|
foreach ( new GlobIterator( $directory . '/*/' . $jsonFilePattern ) as $iterator ) {
|
|
|
|
|
$jsonPath = $iterator->getPathname();
|
|
|
|
|
// ExtensionRegistry->readFromQueue is not used as it checks extension/skin
|
|
|
|
|
// dependencies, which we don't need or want for unit tests.
|
|
|
|
|
$json = file_get_contents( $jsonPath );
|
|
|
|
|
$info = json_decode( $json, true );
|
|
|
|
|
$dir = dirname( $jsonPath );
|
|
|
|
|
ExtensionRegistry::exportAutoloadClassesAndNamespaces( $dir, $info );
|
|
|
|
|
ExtensionRegistry::exportTestAutoloadClassesAndNamespaces( $dir, $info );
|
2019-07-01 19:33:54 +00:00
|
|
|
}
|
|
|
|
|
}
|