From: Kosta Harlan Date: Thu, 5 Sep 2019 07:14:28 +0000 (+0200) Subject: Tests: Provide clearer error when config is accessed via unit test X-Git-Tag: 1.34.0-rc.0~370^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=0ccd20ec18f4d26fcdbd51b9048dd5b47edcd03a;p=lhc%2Fweb%2Fwiklou.git Tests: Provide clearer error when config is accessed via unit test Bug: T231288 Change-Id: I67622f5ed5e9dc901f5b71a6a2f61cbebe51184b --- diff --git a/tests/phpunit/MediaWikiUnitTestCase.php b/tests/phpunit/MediaWikiUnitTestCase.php index 3f876ae4aa..4bd28b7f06 100644 --- a/tests/phpunit/MediaWikiUnitTestCase.php +++ b/tests/phpunit/MediaWikiUnitTestCase.php @@ -20,6 +20,7 @@ */ use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Exception; /** * Base class for unit tests. @@ -84,6 +85,22 @@ abstract class MediaWikiUnitTestCase extends TestCase { } } + /** + * @inheritDoc + */ + protected function runTest() { + try { + return parent::runTest(); + } catch ( ConfigException $exception ) { + throw new Exception( + 'Config variables must be mocked, they cannot be accessed directly in tests which extend ' + . self::class, + $exception->getCode(), + $exception + ); + } + } + protected function tearDown() { if ( !defined( 'HHVM_VERSION' ) ) { // Quick reset between tests