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'
81 'Global failed to correctly set'
87 self::$startGlobals[$globalKey],
89 'Global failed to be restored on tearDown'
98 $globalKey =
'abcdefg1234567';
102 'Global failed to correctly set'
109 'Global failed to be correctly unset'
114 $initialServices = MediaWikiServices::getInstance();
117 $this->assertNotSame( $initialServices, MediaWikiServices::getInstance() );
121 $initialServices = MediaWikiServices::getInstance();
122 $initialService = $initialServices->getDBLoadBalancer();
123 $mockService = $this->getMockBuilder( LoadBalancer::class )
124 ->disableOriginalConstructor()->getMock();
126 $this->
setService(
'DBLoadBalancer', $mockService );
127 $this->assertNotSame(
129 MediaWikiServices::getInstance()->getDBLoadBalancer()
131 $this->assertSame( $mockService, MediaWikiServices::getInstance()->getDBLoadBalancer() );
139 $logger1 = LoggerFactory::getInstance(
'foo' );
140 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
141 $logger2 = LoggerFactory::getInstance(
'foo' );
143 $logger3 = LoggerFactory::getInstance(
'foo' );
145 $this->assertSame( $logger1, $logger3 );
146 $this->assertNotSame( $logger1, $logger2 );
154 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
155 $logger1 = LoggerFactory::getInstance(
'foo' );
157 $logger2 = LoggerFactory::getInstance(
'foo' );
159 $this->assertNotSame( $logger1, $logger2 );
160 $this->assertInstanceOf( \Psr\Log\LoggerInterface::class, $logger2 );
168 $logger1 = LoggerFactory::getInstance(
'baz' );
169 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
170 $this->
setLogger(
'foo', $this->createMock( LoggerInterface::class ) );
172 $logger2 = LoggerFactory::getInstance(
'baz' );
174 $this->assertSame( $logger1, $logger2 );