aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/bootstrap.maintenance.php
diff options
context:
space:
mode:
authorLucas Werkmeister (WMDE) <lucas.werkmeister@wikimedia.de>2022-06-09 14:15:54 +0000
committerLucas Werkmeister (WMDE) <lucas.werkmeister@wikimedia.de>2022-06-09 14:15:54 +0000
commitacae1c510765d26b8bf9e9b8003fc35e080821fb (patch)
tree37a9a1e6984473994d6c791929087fda934339b7 /tests/phpunit/bootstrap.maintenance.php
parent7238dff532d035644b1f3adc41816e8523b35f23 (diff)
downloadmediawikicore-acae1c510765d26b8bf9e9b8003fc35e080821fb.tar.gz
mediawikicore-acae1c510765d26b8bf9e9b8003fc35e080821fb.zip
Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work. This reverts commit 7238dff532d035644b1f3adc41816e8523b35f23. Bug: T310255 Bug: T90875 Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
Diffstat (limited to 'tests/phpunit/bootstrap.maintenance.php')
-rw-r--r--tests/phpunit/bootstrap.maintenance.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/phpunit/bootstrap.maintenance.php b/tests/phpunit/bootstrap.maintenance.php
new file mode 100644
index 000000000000..b083a06edcd0
--- /dev/null
+++ b/tests/phpunit/bootstrap.maintenance.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Bootstrapping for MediaWiki PHPUnit tests when called via the maintenance class tests runner.
+ * This file is included by phpunit and is NOT in the global scope.
+ *
+ * @file
+ */
+
+if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+ echo <<<EOF
+You are running these tests directly from phpunit. You may not have all globals correctly set.
+Running phpunit.php instead is recommended.
+EOF;
+ require_once __DIR__ . "/phpunit.php";
+}
+
+// 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();
+} );
+
+MediaWikiCliOptions::initialize();