* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
* tests/phpunit/phpunit.php is retained but will be removed after CI
jobs and other references on
codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
are removed
* add a default bootstrap.integration.php; unit tests in
composer.json use the non-MW bootstrap file (bootstrap.php)
* Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php
Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
88 lines
3.3 KiB
PHP
88 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Bootstrap file used by default in phpunit.xml.dist.
|
|
*
|
|
* Takes care of preparation needed for integration tests to run.
|
|
*
|
|
* If you want to run unit tests with more strict isolation (ensuring MediaWiki does not bootstrap),
|
|
* then pass the bootstrap.php file, not this one, to vendor/bin/phpunit --bootstrap.
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
require_once __DIR__ . "/bootstrap.php";
|
|
require_once __DIR__ . "/IntegrationBootstrapWrapper.php";
|
|
|
|
if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {
|
|
exit( 'This script must be run from the command line' );
|
|
}
|
|
if ( strval( getenv( 'MW_INSTALL_PATH' ) ) === '' ) {
|
|
putenv( 'MW_INSTALL_PATH=' . realpath( __DIR__ . '/../..' ) );
|
|
}
|
|
if ( getenv( 'PHPUNIT_WIKI' ) ) {
|
|
$wikiName = getenv( 'PHPUNIT_WIKI' );
|
|
$bits = explode( '-', $wikiName, 2 );
|
|
define( 'MW_DB', $bits[0] );
|
|
define( 'MW_PREFIX', $bits[1] ?? '' );
|
|
define( 'MW_WIKI_NAME', $wikiName );
|
|
}
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
global $wgIntegrationBootstrapWrapper;
|
|
$wgIntegrationBootstrapWrapper = new IntegrationBootstrapWrapper();
|
|
$wgIntegrationBootstrapWrapper->setup();
|
|
|
|
require_once "$IP/includes/BootstrapHelperFunctions.php";
|
|
// ensure MW_INSTALL_PATH is defined
|
|
$IP = wfDetectInstallPath();
|
|
wfDetectLocalSettingsFile( $IP );
|
|
|
|
/**
|
|
* Will be called when MW_SETUP_CALLBACK is evaluated during bootstrapping.
|
|
*
|
|
* @return void
|
|
*/
|
|
function wfPHPUnitSetup(): void {
|
|
global $wgIntegrationBootstrapWrapper;
|
|
$wgIntegrationBootstrapWrapper->finalSetup();
|
|
}
|
|
|
|
define( 'MW_SETUP_CALLBACK', 'wfPHPUnitSetup' );
|
|
|
|
MediaWikiIntegrationTestCase::initializeForStandardPhpunitEntrypointIfNeeded();
|
|
|
|
// Deregister handler from MWExceptionHandler::installHandle so that PHPUnit's own handler
|
|
// stays intact. Needs to happen after including Setup.php, which calls MWExceptionHandler::installHandle().
|
|
restore_error_handler();
|
|
|
|
$wgIntegrationBootstrapWrapper->execute();
|
|
|
|
// The TestRunner class will run each test suite and may call
|
|
// exit() with an exit status code. As such, we cannot run code "after the last test"
|
|
// by adding statements to PHPUnitMaintClass::execute.
|
|
// Instead, we work around it by registering a shutdown callback from the bootstrap
|
|
// file, which runs before PHPUnit starts.
|
|
// @todo Once we use PHPUnit 8 or higher, use the 'AfterLastTestHook' feature.
|
|
// https://phpunit.readthedocs.io/en/8.0/extending-phpunit.html#available-hook-interfaces
|
|
register_shutdown_function( static function () {
|
|
// This will:
|
|
// - clear the temporary job queue.
|
|
// - allow extensions to delete any temporary tables they created.
|
|
// - restore ability to connect to the real database.
|
|
MediaWikiIntegrationTestCase::teardownTestDB();
|
|
} );
|