MediaWiki  REL1_24
ConfigFactoryTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ConfigFactoryTest extends MediaWikiTestCase {
00004 
00005     public function tearDown() {
00006         // Reset this since we mess with it a bit
00007         ConfigFactory::destroyDefaultInstance();
00008         parent::tearDown();
00009     }
00010 
00014     public function testRegister() {
00015         $factory = new ConfigFactory();
00016         $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
00017         $this->assertTrue( true ); // No exception thrown
00018         $this->setExpectedException( 'InvalidArgumentException' );
00019         $factory->register( 'invalid', 'Invalid callback' );
00020     }
00021 
00025     public function testMakeConfig() {
00026         $factory = new ConfigFactory();
00027         $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
00028         $conf = $factory->makeConfig( 'unittest' );
00029         $this->assertInstanceOf( 'Config', $conf );
00030     }
00031 
00035     public function testMakeConfigWithNoBuilders() {
00036         $factory = new ConfigFactory();
00037         $this->setExpectedException( 'ConfigException' );
00038         $factory->makeConfig( 'nobuilderregistered' );
00039     }
00040 
00044     public function testMakeConfigWithInvalidCallback() {
00045         $factory = new ConfigFactory();
00046         $factory->register( 'unittest', function () {
00047             return true; // Not a Config object
00048         } );
00049         $this->setExpectedException( 'UnexpectedValueException' );
00050         $factory->makeConfig( 'unittest' );
00051     }
00052 
00056     public function testGetDefaultInstance() {
00057         // Set $wgConfigRegistry, and check the default
00058         // instance read from it
00059         $this->setMwGlobals( 'wgConfigRegistry', array(
00060             'conf1' => 'GlobalVarConfig::newInstance',
00061             'conf2' => 'GlobalVarConfig::newInstance',
00062         ) );
00063         ConfigFactory::destroyDefaultInstance();
00064         $factory = ConfigFactory::getDefaultInstance();
00065         $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf1' ) );
00066         $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf2' ) );
00067         $this->setExpectedException( 'ConfigException' );
00068         $factory->makeConfig( 'conf3' );
00069     }
00070 }