Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiUnitTestCase.php
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4 use PHPUnit\Framework\TestCase;
5
6 abstract class MediaWikiUnitTestCase extends TestCase {
7 use MediaWikiCoversValidator;
8 use PHPUnit4And6Compat;
9
10 /** @var MediaWikiServices $mwServicesBackup */
11 private $mwServicesBackup;
12
13 /**
14 * Replace global MediaWiki service locator with a clone that has the given overrides applied
15 * @param callable[] $overrides map of service names to instantiators
16 * @throws MWException
17 */
18 protected function overrideMwServices( array $overrides ) {
19 $services = clone MediaWikiServices::getInstance();
20
21 foreach ( $overrides as $serviceName => $factory ) {
22 $services->disableService( $serviceName );
23 $services->redefineService( $serviceName, $factory );
24 }
25
26 $this->mwServicesBackup = MediaWikiServices::forceGlobalInstance( $services );
27 }
28
29 protected function tearDown() {
30 parent::tearDown();
31
32 if ( $this->mwServicesBackup ) {
33 MediaWikiServices::forceGlobalInstance( $this->mwServicesBackup );
34 }
35 }
36 }