Clean-up of MediaWikiTestCase::checkHasGzip()
authorOri Livneh <ori@wikimedia.org>
Wed, 1 Jun 2016 17:32:37 +0000 (10:32 -0700)
committerOri Livneh <ori@wikimedia.org>
Wed, 1 Jun 2016 17:44:23 +0000 (10:44 -0700)
* Move the method from MediaWikiTestCase to DumpTestCase. Only subclasses of
  DumpTestCase use it, and it is not sufficiently well-designed to be a part
  of MediaWikiTestCase. (I'd want something more generic, like
  "$this->markSkippedUnlessExecutable()", rather than a method dedicated solely
  to establishing the availability of the gzip binary.)
* Fix it so that the result of the check is actually cached. It wasn't,
  previously, because of how 'static' works in PHP.
* Be content with checking that gzip is in $PATH instead of actually executing
  it.

Change-Id: Iec687a6bfe75912e1875afc3abb4fb6197a0b3aa

tests/phpunit/MediaWikiTestCase.php
tests/phpunit/maintenance/DumpTestCase.php

index e0a7ea3..8dfe628 100644 (file)
@@ -1650,32 +1650,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                }
        }
 
-       /**
-        * Check whether we have the 'gzip' commandline utility, will skip
-        * the test whenever "gzip -V" fails.
-        *
-        * Result is cached at the process level.
-        *
-        * @return bool
-        *
-        * @since 1.21
-        */
-       protected function checkHasGzip() {
-               static $haveGzip;
-
-               if ( $haveGzip === null ) {
-                       $retval = null;
-                       wfShellExec( 'gzip -V', $retval );
-                       $haveGzip = ( $retval === 0 );
-               }
-
-               if ( !$haveGzip ) {
-                       $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
-               }
-
-               return $haveGzip;
-       }
-
        /**
         * Check if $extName is a loaded PHP extension, will skip the
         * test whenever it is not loaded.
index ac83d4e..1d55ab8 100644 (file)
@@ -25,6 +25,26 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
         */
        protected $xml = null;
 
+       /** @var bool|null Whether the 'gzip' utility is available */
+       protected static $hasGzip = null;
+
+       /**
+        * Skip the test if 'gzip' is not in $PATH.
+        *
+        * @return bool
+        */
+       protected function checkHasGzip() {
+               if ( self::$hasGzip === null ) {
+                       self::$hasGzip = ( Installer::locateExecutableInDefaultPaths( 'gzip' ) !== false );
+               }
+
+               if ( !self::$hasGzip ) {
+                       $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
+               }
+
+               return self::$hasGzip;
+       }
+
        /**
         * Adds a revision to a page, while returning the resuting revision's id
         *