X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fbootstrap.php;h=79cb5be3380929c037feb9d8dc002390ebef1c4d;hb=d029197c7c5b083edef20fa79cc3e6d58e161f72;hp=a5c8ef61c43f95be8c820a5062ffaedb99ee67a4;hpb=a3eb5b3a8cf2414964858797ada3551895484ade;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index a5c8ef61c4..79cb5be338 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -14,16 +14,21 @@ EOF; require_once __DIR__ . "/phpunit.php"; } -class MediaWikiPHPUnitBootstrap { - public function __destruct() { - // Return to real wiki db, so profiling data is preserved - MediaWikiTestCase::teardownTestDB(); +// The PHPUnit_TextUI_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 or MediaWikiPHPUnitCommand::run. +// 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( 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, + // (for logging profiling data). + MediaWikiTestCase::teardownTestDB(); - // Log profiling data, e.g. in the database or UDP - wfLogProfilingData(); - } - -} - -// This will be destructed after all tests have been run -$mediawikiPHPUnitBootstrap = new MediaWikiPHPUnitBootstrap(); + // Log profiling data, e.g. in the database or UDP + wfLogProfilingData(); +} );