From: Daniel Friesen Date: Mon, 3 Jun 2013 10:35:35 +0000 (-0700) Subject: Support installing PHPUnit using composer. X-Git-Tag: 1.31.0-rc.0~19474^2 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=2740518620a73d9278a9f78c078dcf0a50bcf3d5;p=lhc%2Fweb%2Fwiklou.git Support installing PHPUnit using composer. "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 --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 07763d95e6..e32d484db4 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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 diff --git a/includes/WebStart.php b/includes/WebStart.php index ead6d77ae6..16658d3863 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -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"; diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 10984b0621..866ec5af67 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -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"; diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php index deef7455fd..e4cb6b6a67 100755 --- a/tests/phpunit/phpunit.php +++ b/tests/phpunit/phpunit.php @@ -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();