Page MenuHomePhabricator

Run MediaWiki tests with PHPUnit 6
Closed, ResolvedPublic

Description

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.

MediaWikiTestCase
+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 {
PHPUnitMaintClass
@@ -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";

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/2713

Event Timeline

mwjames created this task.Sep 30 2017, 12:24 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 30 2017, 12:24 AM

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.

Krinkle added a subscriber: Krinkle.Oct 6 2017, 9:12 PM

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 https://phabricator.wikimedia.org/T147778#3147798, https://gerrit.wikimedia.org/r/#/c/345945/3, 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.

Krinkle updated the task description. (Show Details)Oct 6 2017, 9:12 PM
MaxSem moved this task from Unsorted to PHP 7.1 on the [DO NOT USE] NewPHP board.Oct 17 2017, 5:23 AM

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

https://gerrit.wikimedia.org/r/401650

Krinkle removed a subscriber: Krinkle.Jan 8 2018, 6:17 PM

Change 401650 abandoned by Legoktm:
Use PHPUnit namespaced classes

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

https://gerrit.wikimedia.org/r/401650

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

https://gerrit.wikimedia.org/r/394851

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

https://gerrit.wikimedia.org/r/394851

Jdforrester-WMF closed this task as Resolved.Apr 13 2018, 6:31 PM
Jdforrester-WMF assigned this task to Legoktm.
Jdforrester-WMF removed a project: Patch-For-Review.