From: Timo Tijhof Date: Fri, 4 May 2018 01:15:24 +0000 (+0100) Subject: resourceloader: Improve test coverage of ResourceLoader::register() X-Git-Tag: 1.34.0-rc.0~5532^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=commitdiff_plain;h=94f71346e8f89d5946a0829e083f40b9abc3fb18;p=lhc%2Fweb%2Fwiklou.git resourceloader: Improve test coverage of ResourceLoader::register() Verify that calling register() twice does not throw, but warns, and that the last registration wins. This behaviour was actually surprising to me because it used to throw, and I'd assume that when we added the warning, the behaviour would go from fatal to non-fatal, but keep that the last one is at fault/unsupported. Perhaps b1ea0612 / d3e3bcfd6 (T116628) should've added a return statement. Oh well, we can consider changing that later, but at least test for it. Change-Id: I955132868146ea5bf88c9b9e648c84d8196cb1f9 --- diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index 4e9f5399c5..e811d874ff 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -99,6 +99,22 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { $resourceLoader->register( 'test', new stdClass() ); } + /** + * @covers ResourceLoader::register + */ + public function testRegisterDuplicate() { + $logger = $this->getMockBuilder( Psr\Log\LoggerInterface::class )->getMock(); + $logger->expects( $this->once() ) + ->method( 'warning' ); + $resourceLoader = new EmptyResourceLoader( null, $logger ); + + $module1 = new ResourceLoaderTestModule(); + $module2 = new ResourceLoaderTestModule(); + $resourceLoader->register( 'test', $module1 ); + $resourceLoader->register( 'test', $module2 ); + $this->assertSame( $module2, $resourceLoader->getModule( 'test' ) ); + } + /** * @covers ResourceLoader::getModuleNames */