<?php
+use Wikimedia\ScopedCallback;
+
/**
* @covers ExtensionRegistry
*/
$registry->loadFromQueue();
$this->assertArrayHasKey( 'FooBar', $registry->getAllThings() );
$this->assertTrue( $registry->isLoaded( 'FooBar' ) );
+ $this->assertTrue( $registry->isLoaded( 'FooBar', '*' ) );
$this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
$this->assertSame( [], $registry->getAttribute( 'NotLoadedAttr' ) );
}
+ public function testLoadFromQueueWithConstraintWithVersion() {
+ $registry = new ExtensionRegistry();
+ $registry->queue( "{$this->dataDir}/good_with_version.json" );
+ $registry->loadFromQueue();
+ $this->assertTrue( $registry->isLoaded( 'FooBar', '>= 1.2.0' ) );
+ $this->assertFalse( $registry->isLoaded( 'FooBar', '^1.3.0' ) );
+ }
+
+ /**
+ * @expectedException LogicException
+ */
+ public function testLoadFromQueueWithConstraintWithoutVersion() {
+ $registry = new ExtensionRegistry();
+ $registry->queue( "{$this->dataDir}/good.json" );
+ $registry->loadFromQueue();
+ $registry->isLoaded( 'FooBar', '>= 1.2.0' );
+ }
+
/**
* @expectedException PHPUnit_Framework_Error
*/
],
];
}
+
+ 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' ] );
+ }
}