4use Psr\Log\LoggerInterface;
16 'MediaWikiTestCaseTestGLOBAL-ExistingString' =>
'foo',
17 'MediaWikiTestCaseTestGLOBAL-ExistingStringEmpty' =>
'',
18 'MediaWikiTestCaseTestGLOBAL-ExistingArray' => [ 1,
'foo' =>
'bar' ],
19 'MediaWikiTestCaseTestGLOBAL-ExistingArrayEmpty' => [],
23 parent::setUpBeforeClass();
24 foreach ( self::$startGlobals as $key =>
$value ) {
30 parent::tearDownAfterClass();
31 foreach ( self::$startGlobals as $key =>
$value ) {
38 foreach ( array_keys( self::$startGlobals ) as $key ) {
39 $providedArray[] = [ $key,
'newValue' ];
40 $providedArray[] = [ $key, [
'newValue' ] ];
42 return $providedArray;
56 'Global failed to correctly set'
62 self::$startGlobals[$globalKey],
64 'Global failed to be restored on tearDown'
80 'Global failed to correctly set'
86 self::$startGlobals[$globalKey],
88 'Global failed to be restored on tearDown'
97 $globalKey =
'abcdefg1234567';
101 'Global failed to correctly set'
108 'Global failed to be correctly unset'
113 $initialServices = MediaWikiServices::getInstance();
116 $this->assertNotSame( $initialServices, MediaWikiServices::getInstance() );
119 $this->assertSame( $initialServices, MediaWikiServices::getInstance() );
123 $initialServices = MediaWikiServices::getInstance();
124 $initialService = $initialServices->getDBLoadBalancer();
125 $mockService = $this->getMockBuilder( LoadBalancer::class )
126 ->disableOriginalConstructor()->getMock();
128 $this->
setService(
'DBLoadBalancer', $mockService );
129 $this->assertNotSame( $initialServices, MediaWikiServices::getInstance() );
130 $this->assertNotSame(
132 MediaWikiServices::getInstance()->getDBLoadBalancer()
134 $this->assertSame( $mockService, MediaWikiServices::getInstance()->getDBLoadBalancer() );
137 $this->assertSame( $initialServices, MediaWikiServices::getInstance() );
138 $this->assertNotSame( $mockService, MediaWikiServices::getInstance()->getDBLoadBalancer() );
139 $this->assertSame( $initialService, MediaWikiServices::getInstance()->getDBLoadBalancer() );
147 $logger1 = LoggerFactory::getInstance(
'foo' );
148 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
149 $logger2 = LoggerFactory::getInstance(
'foo' );
151 $logger3 = LoggerFactory::getInstance(
'foo' );
153 $this->assertSame( $logger1, $logger3 );
154 $this->assertNotSame( $logger1, $logger2 );
162 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
163 $logger1 = LoggerFactory::getInstance(
'foo' );
165 $logger2 = LoggerFactory::getInstance(
'foo' );
167 $this->assertNotSame( $logger1, $logger2 );
168 $this->assertInstanceOf( \Psr\Log\LoggerInterface::class, $logger2 );
176 $logger1 = LoggerFactory::getInstance(
'baz' );
177 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
178 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
180 $logger2 = LoggerFactory::getInstance(
'baz' );
182 $this->assertSame( $logger1, $logger2 );