Don't try looking for phpunit if it is already loaded
authorKunal Mehta <legoktm@gmail.com>
Wed, 1 Jul 2015 20:40:53 +0000 (13:40 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 1 Jul 2015 21:36:43 +0000 (21:36 +0000)
If phpunit is installed via composer, it will already be present in the
autoloader, so including other paths won't do anything.

Also add some output to make it easier to figure out where phpunit is
being loaded from.

Change-Id: Id6d23626b158779f6ff56e6d0f20d519f2f4ad18

tests/phpunit/phpunit.php

index 34e3fb4..efde4c0 100755 (executable)
@@ -215,17 +215,23 @@ if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
 
 $ok = false;
 
-foreach ( array(
-       stream_resolve_include_path( 'phpunit.phar' ),
-       'PHPUnit/Runner/Version.php',
-       'PHPUnit/Autoload.php'
-) as $includePath ) {
-       // @codingStandardsIgnoreStart
-       @include_once $includePath;
-       // @codingStandardsIgnoreEnd
-       if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
-               $ok = true;
-               break;
+if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
+       echo "PHPUnit already present\n";
+       $ok = true;
+} else {
+       foreach ( array(
+                               stream_resolve_include_path( 'phpunit.phar' ),
+                               'PHPUnit/Runner/Version.php',
+                               'PHPUnit/Autoload.php'
+                       ) as $includePath ) {
+               // @codingStandardsIgnoreStart
+               @include_once $includePath;
+               // @codingStandardsIgnoreEnd
+               if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
+                       $ok = true;
+                       echo "Using PHPUnit from $includePath\n";
+                       break;
+               }
        }
 }