X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Ftests%2FMediaWikiTestCaseTest.php;h=7d75ffe648d0cf84332a54dfd93ec963c64eaedd;hp=5d2f37e6a64227225ce1d415601c4ecacdd9aab2;hb=c8e482371407477ecd4f0a1b5778e565d3963a93;hpb=a303296f2730d6279a249bde77f3e0b9b42e494f diff --git a/tests/phpunit/tests/MediaWikiTestCaseTest.php b/tests/phpunit/tests/MediaWikiTestCaseTest.php index 5d2f37e6a6..7d75ffe648 100644 --- a/tests/phpunit/tests/MediaWikiTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php @@ -9,8 +9,6 @@ use Psr\Log\LoggerInterface; */ class MediaWikiTestCaseTest extends MediaWikiTestCase { - const GLOBAL_KEY_NONEXISTING = 'MediaWikiTestCaseTestGLOBAL-NONExisting'; - private static $startGlobals = [ 'MediaWikiTestCaseTestGLOBAL-ExistingString' => 'foo', 'MediaWikiTestCaseTestGLOBAL-ExistingStringEmpty' => '', @@ -90,14 +88,22 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { /** * @covers MediaWikiTestCase::stashMwGlobals + * @covers MediaWikiTestCase::tearDown */ - public function testExceptionThrownWhenStashingNonExistentGlobals() { - $this->setExpectedException( - 'Exception', - 'Global with key ' . self::GLOBAL_KEY_NONEXISTING . ' doesn\'t exist and cant be stashed' + public function testSetNonExistentGlobalsAreUnsetOnTearDown() { + $globalKey = 'abcdefg1234567'; + $this->setMwGlobals( $globalKey, true ); + $this->assertTrue( + $GLOBALS[$globalKey], + 'Global failed to correctly set' ); - $this->stashMwGlobals( self::GLOBAL_KEY_NONEXISTING ); + $this->tearDown(); + + $this->assertFalse( + isset( $GLOBALS[$globalKey] ), + 'Global failed to be correctly unset' + ); } public function testOverrideMwServices() { @@ -132,32 +138,41 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { /** * @covers MediaWikiTestCase::setLogger - * @covers MediaWikiTestCase::restoreLogger + * @covers MediaWikiTestCase::restoreLoggers */ - public function testLoggersAreRestoredOnTearDown() { - // replacing an existing logger + public function testLoggersAreRestoredOnTearDown_replacingExistingLogger() { $logger1 = LoggerFactory::getInstance( 'foo' ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( 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' ); + /** + * @covers MediaWikiTestCase::setLogger + * @covers MediaWikiTestCase::restoreLoggers + */ + public function testLoggersAreRestoredOnTearDown_replacingNonExistingLogger() { + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); + $logger1 = LoggerFactory::getInstance( 'foo' ); $this->tearDown(); - $logger2 = LoggerFactory::getInstance( 'bar' ); + $logger2 = LoggerFactory::getInstance( 'foo' ); $this->assertNotSame( $logger1, $logger2 ); $this->assertInstanceOf( '\Psr\Log\LoggerInterface', $logger2 ); + } - // replacing same logger twice + /** + * @covers MediaWikiTestCase::setLogger + * @covers MediaWikiTestCase::restoreLoggers + */ + public function testLoggersAreRestoredOnTearDown_replacingSameLoggerTwice() { $logger1 = LoggerFactory::getInstance( 'baz' ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); $this->tearDown(); $logger2 = LoggerFactory::getInstance( 'baz' );