Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / config / ConfigFactoryTest.php
blob3902858d617f8aa889e0b5959abe70e79d137ee7
1 <?php
3 class ConfigFactoryTest extends MediaWikiTestCase {
5 public function tearDown() {
6 // Reset this since we mess with it a bit
7 ConfigFactory::destroyDefaultInstance();
8 parent::tearDown();
11 /**
12 * @covers ConfigFactory::register
14 public function testRegister() {
15 $factory = new ConfigFactory();
16 $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
17 $this->assertTrue( true ); // No exception thrown
18 $this->setExpectedException( 'InvalidArgumentException' );
19 $factory->register( 'invalid', 'Invalid callback' );
22 /**
23 * @covers ConfigFactory::makeConfig
25 public function testMakeConfig() {
26 $factory = new ConfigFactory();
27 $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
28 $conf = $factory->makeConfig( 'unittest' );
29 $this->assertInstanceOf( 'Config', $conf );
32 /**
33 * @covers ConfigFactory::makeConfig
35 public function testMakeConfigWithNoBuilders() {
36 $factory = new ConfigFactory();
37 $this->setExpectedException( 'ConfigException' );
38 $factory->makeConfig( 'nobuilderregistered' );
41 /**
42 * @covers ConfigFactory::makeConfig
44 public function testMakeConfigWithInvalidCallback() {
45 $factory = new ConfigFactory();
46 $factory->register( 'unittest', function () {
47 return true; // Not a Config object
48 } );
49 $this->setExpectedException( 'UnexpectedValueException' );
50 $factory->makeConfig( 'unittest' );
53 /**
54 * @covers ConfigFactory::getDefaultInstance
56 public function testGetDefaultInstance() {
57 // Set $wgConfigRegistry, and check the default
58 // instance read from it
59 $this->setMwGlobals( 'wgConfigRegistry', array(
60 'conf1' => 'GlobalVarConfig::newInstance',
61 'conf2' => 'GlobalVarConfig::newInstance',
62 ) );
63 ConfigFactory::destroyDefaultInstance();
64 $factory = ConfigFactory::getDefaultInstance();
65 $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf1' ) );
66 $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf2' ) );
67 $this->setExpectedException( 'ConfigException' );
68 $factory->makeConfig( 'conf3' );