Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiUnitTestCase.php
index c1dc0f9..5f7746b 100644 (file)
@@ -30,17 +30,28 @@ use PHPUnit\Framework\TestCase;
 abstract class MediaWikiUnitTestCase extends TestCase {
        use PHPUnit4And6Compat;
        use MediaWikiCoversValidator;
-       use MediaWikiGroupValidator;
 
-       /**
-        * @throws ReflectionException
-        */
+       private $unitGlobals = [];
+
        protected function setUp() {
                parent::setUp();
-               if ( $this->isTestInDatabaseGroup() ) {
-                       throw new \Exception( get_class( $this ) .
-                         ' extends MediaWikiUnitTestCase, and may not have the @group Database annotation.' );
+               $reflection = new ReflectionClass( $this );
+               $dirSeparator = DIRECTORY_SEPARATOR;
+               if ( strpos( $reflection->getFilename(), "${dirSeparator}unit${dirSeparator}" ) === false ) {
+                       $this->fail( 'This unit test needs to be in "tests/phpunit/unit" !' );
+               }
+               $this->unitGlobals = $GLOBALS;
+               unset( $GLOBALS );
+               $GLOBALS = [];
+               // Add back the minimal set of globals needed for unit tests to run for core +
+               // extensions/skins.
+               foreach ( $this->unitGlobals['wgPhpUnitBootstrapGlobals'] ?? [] as $key => $value ) {
+                       $GLOBALS[ $key ] = $this->unitGlobals[ $key ];
                }
        }
 
+       protected function tearDown() {
+               $GLOBALS = $this->unitGlobals;
+               parent::tearDown();
+       }
 }