From b19ff388467ce9fb09ebb32655dc401130102f64 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Wed, 1 Jun 2016 10:32:37 -0700 Subject: [PATCH] Clean-up of MediaWikiTestCase::checkHasGzip() * 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 | 26 ---------------------- tests/phpunit/maintenance/DumpTestCase.php | 20 +++++++++++++++++ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index e0a7ea367e..8dfe628a3f 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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. diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index ac83d4e70a..1d55ab8434 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -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 * -- 2.20.1