wiki.techinc.nl/tests/phpunit/bootstrap.maintenance.php
Daimona Eaytoy 3b32e90931 phpunit: Improve PHPUnit bootstrap files
- Remove display_errors override. This was copied from the Maintenance
  class in Id6d7e9db, but it's unnecessary here because we configure
  PHPUnit to fail if a PHP notice/warning is emitted. This causes the
  warning/notice to be converted to a failed assertion handled by
  PHPUnit.
- Remove code that turned off output buffering, also copied from
  Maintenance. I'd say it's unlikely for output buffering to enabled at
  that point, and most importantly, we would enable output buffering a
  bit later anyway.
- Call ob_start earlier, so that it also works for anything that prints
  messages even before dataProviders are run (e.g., setup or
  bootstrap code).
- Move the ob_start call to the common bootstrap, as unit tests are
  still affected by the same issue that the call aimed to fix.
- Print the PHP version immediately, and do that for unit tests too.
- Get rid of MediaWikiCliOptions in favour of private code in
  MediaWikiIntegrationTestCase, which is the only class supposed to
  access those settings.
- Set wgCommandLineMode in the common bootstrap. Assume that nobody is
  changing its value randomly in config files because that'd be
  ill-advised.
- Inline code for setting memory_limit and max_execution_time, and run
  it only after loading the settings. Doing that earlier is pointless,
  because these values are already set in suite.xml.
- Update obsolete comment mentioning PHPUnitMaintClass, which is long
  gone. In the current code, this is the only way (besides PHPUnit
  hooks/events) to run code before PHP exits. Also remove the second
  part because we're now on PHPUnit 9, so this should be actionable now.
  Remove link to the PHPUnit documentation as it no longer works. There
  doesn't seem to be an equivalent link for PHPUnit 9, perhaps because
  hooks were replaced with events. There //is// an equivalent link in
  the PHPUnit 10 documentation (for events), but we're not yet using it.

Change-Id: I79bbbfcfe4eab3ff5ae81b2deb6450ba06ad7611
2023-07-13 00:46:13 +02:00

29 lines
1.1 KiB
PHP

<?php
/**
* DEPRECATED: This file only exists for BC with tests/phpunit/phpunit.php and will be removed together with it.
*
* @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();
} );