wiki.techinc.nl/tests/phpunit/bootstrap.common.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.3 KiB
PHP
Raw Normal View History

<?php
if ( ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) || defined( 'MEDIAWIKI' ) ) {
exit( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process' );
}
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-09 18:04:26 +00:00
fwrite( STDERR, 'Using PHP ' . PHP_VERSION . "\n" );
define( 'MEDIAWIKI', true );
define( 'MW_ENTRY_POINT', 'cli' );
// Set a flag which can be used to detect when other scripts have been entered
// through this entry point or not.
define( 'MW_PHPUNIT_TEST', true );
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 );
}
require_once __DIR__ . '/../common/TestSetup.php';
require_once __DIR__ . "/../../includes/BootstrapHelperFunctions.php";
// phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix
global $IP;
$IP = wfDetectInstallPath();
// Note: unit tests don't use a settings file but some code still assumes that one exists
wfDetectLocalSettingsFile( $IP );
if ( getenv( 'MW_INSTALL_PATH' ) === false ) {
// Set the env variable for BC with maintenance scripts and the like
putenv( 'MW_INSTALL_PATH=' . $IP );
}
TestSetup::snapshotGlobals();
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-09 18:04:26 +00:00
// Start an output buffer to avoid headers being sent by constructors,
// data providers, etc. (T206476)
ob_start();