Merge "Provide command to adjust phpunit.xml for code coverage"
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionRegistryTest.php
index 1baa79c..106cca3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\ScopedCallback;
+
 /**
  * @covers ExtensionRegistry
  */
@@ -17,7 +19,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                $path = __DIR__ . '/doesnotexist.json';
                $this->setExpectedException(
                        Exception::class,
-                       "$path does not exist!"
+                       "file $path"
                );
                $registry->queue( $path );
        }
@@ -399,4 +401,28 @@ class ExtensionRegistryTest extends MediaWikiTestCase {
                        ],
                ];
        }
+
+       public function testSetAttributeForTest() {
+               $registry = new ExtensionRegistry();
+               $registry->queue( "{$this->dataDir}/good.json" );
+               $registry->loadFromQueue();
+               // Sanity check that it worked
+               $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
+               $reset = $registry->setAttributeForTest( 'FooBarAttr', [ 'override' ] );
+               // overridden properly
+               $this->assertSame( [ 'override' ], $registry->getAttribute( 'FooBarAttr' ) );
+               ScopedCallback::consume( $reset );
+               // reset properly
+               $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
+       }
+
+       /**
+        * @expectedException Exception
+        * @expectedExceptionMessage The attribute 'foo' has already been overridden
+        */
+       public function testSetAttributeForTestDuplicate() {
+               $registry = new ExtensionRegistry();
+               $reset1 = $registry->setAttributeForTest( 'foo', [ 'val1' ] );
+               $reset2 = $registry->setAttributeForTest( 'foo', [ 'val2' ] );
+       }
 }