From: Antoine Musso Date: Mon, 28 Jan 2013 09:27:31 +0000 (+0100) Subject: test: helper to skip tests depending on a PHP ext X-Git-Tag: 1.31.0-rc.0~20891 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=a7901801b4cba6e5a2e543497f0b173a86e1a58b;p=lhc%2Fweb%2Fwiklou.git test: helper to skip tests depending on a PHP ext Some of our tests expect a specific PHP extension to be loaded to get anything done, for example zlib or gd. This patch creates a new helping method that people can use to easily skip a test whenever a PHP extension is not around: MediaWikiTestCase::checkPHPExtension() Example usage: function testCompressFiles() { $this->checkPHPExtension( 'zlib' ); ... } Change-Id: Ia87317ca379b2d5d1d1fa4231f76033ee66086c2 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index cbf9a8e4fc..61b3119ead 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -862,6 +862,20 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + /** + * Check if $extName is a loaded PHP extension, will skip the + * test whenever it is not loaded. + * + * @since 1.21 + */ + protected function checkPHPExtension( $extName ) { + $loaded = extension_loaded( $extName ); + if( ! $loaded ) { + $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." ); + } + return $loaded; + } + /** * Asserts that an exception of the specified type occurs when running * the provided code.