From: addshore Date: Mon, 5 May 2014 16:40:54 +0000 (+0100) Subject: Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point X-Git-Tag: 1.31.0-rc.0~14620 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=33ea33f7b6ed196343a7934926a24a0055cb87b2;p=lhc%2Fweb%2Fwiklou.git Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point MediaWiki tends to assume installation of phpunit via PEAR. Distribution of phpunit via PEAR will eventually be discontinued, in favor of distribution via PHAR or composer. PEAR installation of phpunit 4.0 essentially distributes a phar. https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.0.0 This patch allows phpunit.php to work with a phpunit.phar file, as long as it's in the include path. --with-phpunitdir can be used to add a directory to the include path. With composer install, no options are needed and it works. Bug: 58881 Change-Id: Ibac9b36bbb9614d990c697a091947a64c8987d1d --- diff --git a/.gitignore b/.gitignore index 0351cf5d81..93c429fc0a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ sftp-config.json # Building & testing node_modules/ +/tests/phpunit/phpunit.phar # Composer /vendor diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php index d3231884a8..7dd932fed4 100755 --- a/tests/phpunit/phpunit.php +++ b/tests/phpunit/phpunit.php @@ -103,17 +103,12 @@ class PHPUnitMaintClass extends Maintenance { } # --with-phpunitdir let us override the default PHPUnit version + # Can use with either or phpunit.phar in the directory or the + # full PHPUnit code base. if ( $this->hasOption( 'with-phpunitdir' ) ) { $phpunitDir = $this->getOption( 'with-phpunitdir' ); - # Sanity checks - if ( !is_dir( $phpunitDir ) ) { - $this->error( "--with-phpunitdir should be set to an existing directory", 1 ); - } - if ( !is_readable( $phpunitDir . "/PHPUnit/Runner/Version.php" ) ) { - $this->error( "No usable PHPUnit installation in $phpunitDir.\nAborting.\n", 1 ); - } - # Now prepends provided PHPUnit directory + # prepends provided PHPUnit directory or phar $this->output( "Will attempt loading PHPUnit from `$phpunitDir`\n" ); set_include_path( $phpunitDir . PATH_SEPARATOR . get_include_path() ); @@ -203,18 +198,12 @@ class PHPUnitMaintClass extends Maintenance { $maintClass = 'PHPUnitMaintClass'; require RUN_MAINTENANCE_IF_MAIN; -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.7.0', '<' ) -) { - die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" ); -} +$pharFile = stream_resolve_include_path( 'phpunit.phar' ); +$isValidPhar = Phar::isValidPharFilename( $pharFile ); -if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) { - require_once 'PHPUnit/Autoload.php'; +if ( !$isValidPhar && !class_exists( 'PHPUnit_Runner_Version' ) ) { + // try loading phpunit via PEAR + require_once 'PHPUnit/Runner/Version.php'; } // Prevent segfault when we have lots of unit tests (bug 62623) @@ -227,4 +216,18 @@ if ( version_compare( PHP_VERSION, '5.4.0', '<' ) } ); } -PHPUnit_TextUI_Command::main(); +if ( $isValidPhar ) { + require $pharFile; +} else { + if ( PHPUnit_Runner_Version::id() !== '@package_version@' + && version_compare( PHPUnit_Runner_Version::id(), '3.7.0', '<' ) + ) { + die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" ); + } + + if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) { + require_once 'PHPUnit/Autoload.php'; + } + + PHPUnit_TextUI_Command::main(); +}