X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiUnitTestCase.php;h=43a333cb885e4872855e1023d911835712355e0e;hb=c05b8b7c473a7dd9c832f91366c45cb8a35c2df2;hp=c1dc0f909942944ff5af20f0571ae69d725a0889;hpb=2e0cf0891444367942677692cf8efde87f19c3ef;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiUnitTestCase.php b/tests/phpunit/MediaWikiUnitTestCase.php index c1dc0f9099..43a333cb88 100644 --- a/tests/phpunit/MediaWikiUnitTestCase.php +++ b/tests/phpunit/MediaWikiUnitTestCase.php @@ -30,17 +30,27 @@ 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 ); + if ( strpos( $reflection->getFilename(), '/unit/' ) === 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(); + } }