Support installing PHPUnit using composer.
authorDaniel Friesen <daniel@nadir-seen-fire.com>
Mon, 3 Jun 2013 10:35:35 +0000 (03:35 -0700)
committerDaniel Friesen <daniel@nadir-seen-fire.com>
Fri, 7 Jun 2013 09:07:27 +0000 (02:07 -0700)
"phpunit/phpunit" already exists inside our composer.json's "require-dev" however this has been
entirely useless as we don't include the autoloader which would load composer's PHPUnit.

This change begins including composer's autoloader when present and also tweaks phpunit.php
to ensure PHPUnit isn't double loaded. As a result besides supporting PHPUnit via composer this
also means that we're ready to make use of any library we add to our composer.json in the future.

Change-Id: I891740e8fd3d237c5f473862027205d951f564b9

RELEASE-NOTES-1.22
includes/WebStart.php
maintenance/doMaintenance.php
tests/phpunit/phpunit.php

index 07763d9..e32d484 100644 (file)
@@ -100,6 +100,7 @@ production.
   handlers can take further action based on the status of the patrol footer
 * LinkCache singleton can now be altered or cleared, letting one to specify
   another instance that does not rely on a database backend.
+* MediaWiki's PHPUnit tests can now use PHPUnit installed using composer --dev.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
index ead6d77..16658d3 100644 (file)
@@ -91,6 +91,11 @@ if ( $IP === false ) {
        }
 }
 
+# Load composer's autoloader if present
+if ( is_readable( "$IP/vendor/autoload.php" ) ) {
+       require_once "$IP/vendor/autoload.php";
+}
+
 # Get MWInit class
 require_once "$IP/includes/Init.php";
 
index 10984b0..866ec5a 100644 (file)
@@ -53,9 +53,13 @@ $maintenance->setup();
 // to $maintenance->mSelf. Keep that here for b/c
 $self = $maintenance->getName();
 
-// Detect compiled mode
+# Load composer's autoloader if present
+if ( is_readable( "$IP/vendor/autoload.php" ) ) {
+       require_once "$IP/vendor/autoload.php";
+}
 # Get the MWInit class
 require_once "$IP/includes/Init.php";
+# Start the autoloader, so that extensions can derive classes from core files
 require_once "$IP/includes/AutoLoader.php";
 # Stub the profiler
 require_once "$IP/includes/profiler/Profiler.php";
index deef745..e4cb6b6 100755 (executable)
@@ -103,12 +103,17 @@ class PHPUnitMaintClass extends Maintenance {
 $maintClass = 'PHPUnitMaintClass';
 require RUN_MAINTENANCE_IF_MAIN;
 
-require_once 'PHPUnit/Runner/Version.php';
+if ( !class_exists( 'PHPUnit_Runner_Version') ) {
+       require_once 'PHPUnit/Runner/Version.php';
+}
 
 if ( PHPUnit_Runner_Version::id() !== '@package_version@'
        && version_compare( PHPUnit_Runner_Version::id(), '3.6.7', '<' )
 ) {
        die( 'PHPUnit 3.6.7 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
 }
-require_once 'PHPUnit/Autoload.php';
+
+if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
+       require_once 'PHPUnit/Autoload.php';
+}
 MediaWikiPHPUnitCommand::main();