From 94f71346e8f89d5946a0829e083f40b9abc3fb18 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 4 May 2018 02:15:24 +0100 Subject: [PATCH] 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 --- .../resourceloader/ResourceLoaderTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 */ -- 2.20.1