2010-12-14 16:26:35 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrapping for MediaWiki PHPUnit tests
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-08-10 05:17:59 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
2022-03-31 11:15:27 +00:00
|
|
|
use PHPUnit\TextUI\Command;
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
class PHPUnitMaintClass {
|
|
|
|
|
public function setup() {
|
|
|
|
|
// 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 );
|
2021-01-08 02:16:02 +00:00
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
// Send PHP warnings and errors to stderr instead of stdout.
|
|
|
|
|
// This aids in diagnosing problems, while keeping messages
|
|
|
|
|
// out of redirected output.
|
|
|
|
|
if ( ini_get( 'display_errors' ) ) {
|
|
|
|
|
ini_set( 'display_errors', 'stderr' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->prepareEnvironment();
|
|
|
|
|
require_once __DIR__ . '/../common/TestSetup.php';
|
|
|
|
|
TestSetup::snapshotGlobals();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function prepareEnvironment() {
|
|
|
|
|
# Disable the memory limit as it's not needed for tests.
|
|
|
|
|
ini_set( 'memory_limit', -1 );
|
|
|
|
|
|
|
|
|
|
# Set max execution time to 0 (no limit). PHP.net says that
|
|
|
|
|
# "When running PHP from the command line the default setting is 0."
|
|
|
|
|
# But sometimes this doesn't seem to be the case.
|
|
|
|
|
ini_set( 'max_execution_time', 0 );
|
|
|
|
|
|
|
|
|
|
# Turn off output buffering if it's on
|
|
|
|
|
while ( ob_get_level() > 0 ) {
|
|
|
|
|
ob_end_flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function finalSetup() {
|
|
|
|
|
global $wgDBadminuser, $wgDBadminpassword;
|
|
|
|
|
global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
|
|
|
|
|
|
|
|
|
|
# Prepare environment again, things might have changed in the settings files
|
|
|
|
|
$this->prepareEnvironment();
|
|
|
|
|
|
|
|
|
|
if ( isset( $wgDBadminuser ) ) {
|
|
|
|
|
$wgDBuser = $wgDBadminuser;
|
|
|
|
|
$wgDBpassword = $wgDBadminpassword;
|
|
|
|
|
|
|
|
|
|
if ( $wgDBservers ) {
|
|
|
|
|
/**
|
|
|
|
|
* @var array $wgDBservers
|
|
|
|
|
*/
|
|
|
|
|
foreach ( $wgDBservers as $i => $server ) {
|
|
|
|
|
$wgDBservers[$i]['user'] = $wgDBuser;
|
|
|
|
|
$wgDBservers[$i]['password'] = $wgDBpassword;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $wgLBFactoryConf['serverTemplate'] ) ) {
|
|
|
|
|
$wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
|
|
|
|
|
$wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
|
|
|
|
|
}
|
|
|
|
|
$service = MediaWikiServices::getInstance()->peekService( 'DBLoadBalancerFactory' );
|
|
|
|
|
if ( $service ) {
|
|
|
|
|
$service->destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../common/TestsAutoLoader.php';
|
|
|
|
|
|
|
|
|
|
TestSetup::applyInitialConfig();
|
|
|
|
|
|
|
|
|
|
ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces( true );
|
|
|
|
|
}
|
2012-04-17 13:39:15 +00:00
|
|
|
|
|
|
|
|
public function execute() {
|
2020-05-25 03:48:42 +00:00
|
|
|
// Start an output buffer to avoid headers being sent by constructors,
|
|
|
|
|
// data providers, etc. (T206476)
|
|
|
|
|
ob_start();
|
2022-06-09 14:15:54 +00:00
|
|
|
|
|
|
|
|
fwrite( STDERR, 'Using PHP ' . PHP_VERSION . "\n" );
|
2016-08-31 02:53:21 +00:00
|
|
|
|
2022-03-31 11:15:27 +00:00
|
|
|
$command = new Command();
|
|
|
|
|
$args = $_SERVER['argv'];
|
2022-04-01 03:47:26 +00:00
|
|
|
$knownOpts = getopt( 'c:', [ 'configuration:', 'bootstrap:' ] ) ?: [];
|
|
|
|
|
if ( !isset( $knownOpts['c'] ) && !isset( $knownOpts['configuration'] ) ) {
|
2022-03-31 11:15:27 +00:00
|
|
|
// XXX HAX: Use our default file. This is a temporary hack, to be removed when this file goes away
|
|
|
|
|
// or when T227900 is resolved.
|
2022-06-09 14:15:54 +00:00
|
|
|
$args[] = '--configuration=' . __DIR__ . '/suite.xml';
|
2022-03-31 11:15:27 +00:00
|
|
|
}
|
2025-01-13 13:51:16 +00:00
|
|
|
if ( !isset( $knownOpts['bootstrap'] ) ) {
|
|
|
|
|
$args[] = '--bootstrap=' . __DIR__ . '/bootstrap.maintenance.php';
|
|
|
|
|
}
|
2022-03-31 11:15:27 +00:00
|
|
|
$command->run( $args, true );
|
2012-04-17 13:39:15 +00:00
|
|
|
}
|
2021-03-16 17:25:01 +00:00
|
|
|
}
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
|
2023-07-02 17:14:27 +00:00
|
|
|
$deprecationMsg = <<<EOT
|
|
|
|
|
*******************************************************************************
|
|
|
|
|
DEPRECATED: The tests/phpunit/phpunit.php entry point has been deprecated. Use
|
2023-07-13 15:31:49 +00:00
|
|
|
`composer phpunit` instead.
|
2023-07-02 17:14:27 +00:00
|
|
|
*******************************************************************************
|
|
|
|
|
|
|
|
|
|
EOT;
|
|
|
|
|
|
|
|
|
|
fwrite( STDERR, $deprecationMsg );
|
|
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
if ( defined( 'MEDIAWIKI' ) ) {
|
|
|
|
|
exit( 'Wrong entry point?' );
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-31 12:59:27 +00:00
|
|
|
if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {
|
|
|
|
|
exit( 'This script must be run from the command line' );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
define( 'MW_ENTRY_POINT', 'cli' );
|
|
|
|
|
|
2021-03-16 17:25:01 +00:00
|
|
|
if ( strval( getenv( 'MW_INSTALL_PATH' ) ) === '' ) {
|
|
|
|
|
putenv( 'MW_INSTALL_PATH=' . realpath( __DIR__ . '/../..' ) );
|
2011-02-21 23:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-31 12:59:27 +00:00
|
|
|
if ( getenv( 'PHPUNIT_WIKI' ) ) {
|
2021-12-12 21:20:17 +00:00
|
|
|
$wikiName = getenv( 'PHPUNIT_WIKI' );
|
|
|
|
|
$bits = explode( '-', $wikiName, 2 );
|
2022-03-31 12:59:27 +00:00
|
|
|
define( 'MW_DB', $bits[0] );
|
|
|
|
|
define( 'MW_PREFIX', $bits[1] ?? '' );
|
2021-12-12 21:20:17 +00:00
|
|
|
define( 'MW_WIKI_NAME', $wikiName );
|
2022-03-31 12:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
// Define the MediaWiki entrypoint
|
2022-06-09 14:15:54 +00:00
|
|
|
define( 'MEDIAWIKI', true );
|
2023-07-13 15:31:49 +00:00
|
|
|
|
|
|
|
|
define( 'PHPUNIT_LEGACY_ENTRYPOINT', true );
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
$wrapper = new PHPUnitMaintClass();
|
|
|
|
|
$wrapper->setup();
|
2022-03-31 12:59:27 +00:00
|
|
|
|
2022-04-23 13:31:03 +00:00
|
|
|
require_once "$IP/includes/BootstrapHelperFunctions.php";
|
2022-04-27 19:33:22 +00:00
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
$IP = wfDetectInstallPath(); // ensure MW_INSTALL_PATH is defined
|
2022-03-31 12:59:27 +00:00
|
|
|
wfDetectLocalSettingsFile( $IP );
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
function wfPHPUnitSetup() {
|
|
|
|
|
// phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix
|
|
|
|
|
global $wrapper;
|
|
|
|
|
$wrapper->finalSetup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
define( 'MW_SETUP_CALLBACK', 'wfPHPUnitSetup' );
|
|
|
|
|
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
require_once "$IP/includes/Setup.php";
|
2022-03-31 12:59:27 +00:00
|
|
|
// Deregister handler from MWExceptionHandler::installHandle so that PHPUnit's own handler
|
|
|
|
|
// stays in tact. Needs to happen after including Setup.php, which calls MWExceptionHandler::installHandle().
|
|
|
|
|
restore_error_handler();
|
Decouple phpunit.php from Maintenance
This patch makes phpunit.php not inherit from Maintenance, by copying
relevant code directly into this file. Some now-constant conditionals
and other unnecessary pieces of code were removed/simplified.
Some maintenance-generic options were also removed:
- conf, since eventually LocalSettings shouldn't be used at all
- globals, as it doesn't seem useful here
- memory-limit, should be handled separately
- server, doesn't seem useful
- profiler, ditto
'help', 'wiki' and 'db*' were left for now, but might be removed later.
The next step is removing more unnecessary stuff, until this script
won't be needed at all.
As you may notice, there are some leftovers/wrong references in the
script that weren't cleaned up. I didn't want to waste any time doing
that, as they're going to be killed anyway.
Bug: T90875
Change-Id: Id6d7e9dbfe4bc83a6bc8238d048d3b8634e832e4
2021-03-16 17:01:59 +00:00
|
|
|
|
2023-02-24 09:54:49 +00:00
|
|
|
// Check that composer dependencies are up-to-date
|
|
|
|
|
if ( !getenv( 'MW_SKIP_EXTERNAL_DEPENDENCIES' ) ) {
|
|
|
|
|
$composerLockUpToDate = new CheckComposerLockUpToDate();
|
|
|
|
|
$composerLockUpToDate->loadParamsAndArgs( 'phpunit', [ 'quiet' => true ] );
|
|
|
|
|
$composerLockUpToDate->execute();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 14:15:54 +00:00
|
|
|
$wrapper->execute();
|