<?php
+use MediaWiki\Logger\LoggerFactory;
+use Psr\Log\LoggerInterface;
/**
* @covers MediaWikiTestCase
const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting';
- private static $startGlobals = array(
+ private static $startGlobals = [
'MediaWikiTestCaseTestGLOBAL-ExistingString' => 'foo',
'MediaWikiTestCaseTestGLOBAL-ExistingStringEmpty' => '',
- 'MediaWikiTestCaseTestGLOBAL-ExistingArray' => array( 1, 'foo' => 'bar' ),
- 'MediaWikiTestCaseTestGLOBAL-ExistingArrayEmpty' => array(),
- );
+ 'MediaWikiTestCaseTestGLOBAL-ExistingArray' => [ 1, 'foo' => 'bar' ],
+ 'MediaWikiTestCaseTestGLOBAL-ExistingArrayEmpty' => [],
+ ];
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
}
public function provideExistingKeysAndNewValues() {
- $providedArray = array();
+ $providedArray = [];
foreach ( array_keys( self::$startGlobals ) as $key ) {
- $providedArray[] = array( $key, 'newValue' );
- $providedArray[] = array( $key, array( 'newValue' ) );
+ $providedArray[] = [ $key, 'newValue' ];
+ $providedArray[] = [ $key, [ 'newValue' ] ];
}
return $providedArray;
}
$this->stashMwGlobals( self::GLOBAL_KEY_NONEXISTING );
}
+ /**
+ * @covers MediaWikiTestCase::setLogger
+ * @covers MediaWikiTestCase::restoreLogger
+ */
+ public function testLoggersAreRestoredOnTearDown() {
+ // replacing an existing logger
+ $logger1 = LoggerFactory::getInstance( 'foo' );
+ $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) );
+ $logger2 = LoggerFactory::getInstance( 'foo' );
+ $this->tearDown();
+ $logger3 = LoggerFactory::getInstance( 'foo' );
+
+ $this->assertSame( $logger1, $logger3 );
+ $this->assertNotSame( $logger1, $logger2 );
+
+ // replacing a non-existing logger
+ $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) );
+ $logger1 = LoggerFactory::getInstance( 'bar' );
+ $this->tearDown();
+ $logger2 = LoggerFactory::getInstance( 'bar' );
+
+ $this->assertNotSame( $logger1, $logger2 );
+ $this->assertInstanceOf( '\Psr\Log\LoggerInterface', $logger2 );
+
+ // replacing same logger twice
+ $logger1 = LoggerFactory::getInstance( 'baz' );
+ $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) );
+ $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) );
+ $this->tearDown();
+ $logger2 = LoggerFactory::getInstance( 'baz' );
+
+ $this->assertSame( $logger1, $logger2 );
+ }
}