Page MenuHomePhabricator

Run MediaWiki tests with PHPUnit 6
Closed, ResolvedPublic


For those who want to run PHPUnit 6.x on MediaWiki (1.30+, PHP 7.1+, as done in [0]), the following changes are at least required so that we were able to pass our tests.

+use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
+use PHPUnit\Framework\TestResult as PHPUnit_Framework_TestResult;
  * @since 1.18
 abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
@@ -77,11 +77,15 @@ class PHPUnitMaintClass extends Maintenance {
 			// Hack to eliminate the need to use the Makefile (which sucks ATM)
 			array_splice( $_SERVER['argv'], 1, 0,
 				[ '--configuration', $IP . '/tests/phpunit/suite.xml' ] );
-		$phpUnitClass = 'PHPUnit_TextUI_Command';
+		if ( class_exists( '\PHPUnit\TextUI\Command' ) ) {
+			$phpUnitClass = '\PHPUnit\TextUI\Command';
+		} else {
+			$phpUnitClass = 'PHPUnit_TextUI_Command';
+		}
 		if ( $this->hasOption( 'with-phpunitclass' ) ) {
 			$phpUnitClass = $this->getOption( 'with-phpunitclass' );
 			# Cleanup $args array so the option and its value do not
@@ -110,11 +114,11 @@ class PHPUnitMaintClass extends Maintenance {
 					self::$additionalOptions[$option] = true;
-		if ( !class_exists( 'PHPUnit_Framework_TestCase' ) ) {
+		if ( !class_exists( 'PHPUnit_Framework_TestCase' ) && !class_exists( '\PHPUnit\Framework\TestCase' ) ) {
 			echo "PHPUnit not found. Please install it and other dev dependencies by
 		running `composer install` in MediaWiki root directory.\n";


Event Timeline

Thanks for taking a look at the code. You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again.

This is more of a status report on running PHPUnit 6.x/PHP 7.1 with MediaWiki since I needed to modify core in order for our tests to pass. Whether the provided information are of interest or value to developers I don't know, I just wanted to disseminate our experience on the related matter.

Thanks @mwjames. This is quite useful.

Earlier this year and last year I also had to make similar adjustments during an attempt to improve the PHPUnit Code coverage runs by using a newer PHPUnit version which has a significantly faster coverage collector.

Results at T147778: Switch MediaWiki coverage job from PHP 5 to PHP 7
Including,, and various other minor changes that ended up getting merged at the time helped make the same unit tests work on both PHPUnit 5, and the currently used PHPUnit 4.x.

Change 401650 had a related patch set uploaded (by Legoktm; owner: Legoktm):
[mediawiki/core@master] Use PHPUnit namespaced classes

Change 401650 abandoned by Legoktm:
Use PHPUnit namespaced classes

I'll let PHPCS take care of this in the next version.

Legoktm added a subscriber: Legoktm.

I've removed T172165: Require either PHP 7.0+ or HHVM in MW 1.31 as a blocker, since we can upgrade to PHPUnit 6 (theoretically) while continuing to run PHPUnit 4. And once we require minimum PHP 7, we can drop PHPUnit 4.

Legoktm renamed this task from Running PHPUnit 6.x to Run MediaWiki tests with PHPUnit 6.Feb 24 2018, 6:25 AM

Change 394851 had a related patch set uploaded (by Legoktm; owner: Reedy):
[mediawiki/core@master] Allow PHPUnit 6 optionally in require-dev

Change 394851 merged by jenkins-bot:
[mediawiki/core@master] Allow PHPUnit 6 optionally in require-dev