resourceloader: Improve test coverage of ResourceLoader::register()
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 4 May 2018 01:15:24 +0000 (02:15 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 4 May 2018 01:15:24 +0000 (02:15 +0100)
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

tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 4e9f539..e811d87 100644 (file)
@@ -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
         */