Use $this->getServiceContainer() in tests

Change-Id: I7139a34a6373edd8bd6f42d8716260ef2164e8de
This commit is contained in:
Fomafix 2024-07-27 07:40:08 +00:00
parent 30e24aa1b0
commit 156193fe88
3 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,6 @@ use ConfigException;
use CookieWarning\Decisions;
use CookieWarning\GeoLocation;
use HashBagOStuff;
use MediaWiki\MediaWikiServices;
use MediaWikiIntegrationTestCase;
use MWException;
use RequestContext;
@ -32,10 +31,10 @@ class DecisionsTest extends MediaWikiIntegrationTestCase {
$geoLocation->expects( $this->once() )->method( 'locate' );
$cookieWarningDecisions = new Decisions(
MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' ),
$this->getServiceContainer()->getService( 'CookieWarning.Config' ),
$geoLocation,
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
MediaWikiServices::getInstance()->getUserOptionsLookup()
$this->getServiceContainer()->getUserOptionsLookup()
);
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );

View file

@ -6,7 +6,6 @@ use CookieWarning\GeoLocation;
use CookieWarning\Hooks;
use DerivativeContext;
use FauxRequest;
use MediaWiki\MediaWikiServices;
use MediaWikiLangTestCase;
use RequestContext;
use SkinTemplate;
@ -40,7 +39,7 @@ class HooksTest extends MediaWikiLangTestCase {
'CookieWarningMoreUrl' => $morelinkConfig,
'CookieWarningForCountryCodes' => false,
] );
MediaWikiServices::getInstance()->getMessageCache()->enable();
$this->getServiceContainer()->getMessageCache()->enable();
if ( $morelinkCookieWarningMsg ) {
$this->editPage(

View file

@ -4,7 +4,6 @@ namespace CookieWarning\Tests;
use CookieWarning\HttpGeoLocation;
use CookieWarning\NoopGeoLocation;
use MediaWiki\MediaWikiServices;
use MediaWikiIntegrationTestCase;
class ServiceWiringTest extends MediaWikiIntegrationTestCase {
@ -17,7 +16,7 @@ class ServiceWiringTest extends MediaWikiIntegrationTestCase {
'CookieWarningGeoIPServiceURL' => null
] );
$geoLocation = MediaWikiServices::getInstance()->getService( 'GeoLocation' );
$geoLocation = $this->getServiceContainer()->getService( 'GeoLocation' );
$this->assertInstanceOf( NoopGeoLocation::class, $geoLocation );
}
@ -30,7 +29,7 @@ class ServiceWiringTest extends MediaWikiIntegrationTestCase {
'CookieWarningGeoIPServiceURL' => 'http://localhost/'
] );
$geoLocation = MediaWikiServices::getInstance()->getService( 'GeoLocation' );
$geoLocation = $this->getServiceContainer()->getService( 'GeoLocation' );
$this->assertInstanceOf( HttpGeoLocation::class, $geoLocation );
}