Merge "Tests: Provide clearer error when config is accessed via unit test"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Sep 2019 19:26:10 +0000 (19:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Sep 2019 19:26:10 +0000 (19:26 +0000)
tests/phpunit/MediaWikiUnitTestCase.php

index 3f876ae..4bd28b7 100644 (file)
@@ -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