config = new Config(); } public function testGetConfigClass() { $this->assertInstanceOf('FuzeWorks\Config', $this->config); } /** * @depends testGetConfigClass */ public function testLoadConfig() { $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('main')); } /** * @depends testLoadConfig * @expectedException FuzeWorks\Exception\ConfigException */ public function testFileNotFound() { $this->config->getConfig('notFound'); } /** * @depends testLoadConfig */ public function testLoadConfigCancel() { // Register listener Events::addListener(function($event){ $event->setCancelled(true); }, 'configGetEvent', EventPriority::NORMAL); // Attempt and load a config file $config = $this->config->getConfig('loadConfigCancel'); $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $config); $this->assertEmpty($config->toArray()); } /** * @depends testLoadConfig */ public function testLoadConfigIntercept() { // Register listener Events::addListener(function($event){ /** @var ConfigGetEvent $event */ $event->configName = 'testLoadConfigIntercept'; }, 'configGetEvent', EventPriority::NORMAL); // Load file $config = $this->config->getConfig('does_not_exist', ['test'.DS.'config'.DS.'testLoadConfigIntercept']); $this->assertEquals('exists', $config->it); } /** * @depends testLoadConfig * @covers \FuzeWorks\Config::overrideConfig * @covers \FuzeWorks\Config::loadConfigFile */ public function testLoadConfigOverride() { // Load file without override $this->assertEquals(['initial' => 'value'], $this->config->getConfig('testLoadConfigOverride', ['test'.DS.'config'.DS.'testLoadConfigOverride'])->toArray()); // Discard to reset test $this->config->discardConfigFiles(); // Create override Config::overrideConfig('testLoadConfigOverride', 'initial', 'different'); $this->assertEquals(['initial' => 'different'], $this->config->getConfig('testLoadConfigOverride', ['test'.DS.'config'.DS.'testLoadConfigOverride'])->toArray()); } /** * @expectedException FuzeWorks\Exception\ConfigException */ public function testAddConfigPathFail() { // Now test if the config can be loaded (hint: it can not) $this->config->getConfig('testAddConfigPath'); } /** * @depends testAddConfigPathFail */ public function testAddConfigPath() { // Add the configPath $this->config->addConfigPath('test'.DS.'config'.DS.'testAddConfigPath'); // And try to load it again $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('testAddConfigPath')); } public function testRemoveConfigPath() { // Test if the path does NOT exist $this->assertFalse(in_array('test'.DS.'config'.DS.'testRemoveConfigPath', $this->config->getConfigPaths())); // Add it $this->config->addConfigPath('test'.DS.'config'.DS.'testRemoveConfigPath'); // Assert if it's there $this->assertTrue(in_array('test'.DS.'config'.DS.'testRemoveConfigPath', $this->config->getConfigPaths())); // Remove it $this->config->removeConfigPath('test'.DS.'config'.DS.'testRemoveConfigPath'); // And test if it's gone again $this->assertFalse(in_array('test'.DS.'config'.DS.'testRemoveConfigPath', $this->config->getConfigPaths())); } public function testSameConfigObject() { $config = $this->config->getConfig('testsameconfigobject', array('test'.DS.'config'.DS.'testSameConfigObject')); $config2 = $this->config->getConfig('testsameconfigobject', array('test'.DS.'config'.DS.'testSameConfigObject')); // First test if the objects are the same instance $this->assertSame($config, $config2); // First test the existing key $this->assertEquals($config->key, 'value'); // Change it and test if it's different now $config->key = 'other_value'; $this->assertEquals($config2->key, 'other_value'); } public function testSetDirectories() { // Add the directory $directory = 'test' . DS . 'config'; $this->config->setDirectories([$directory]); // Assert expectations $expected = array_merge(\FuzeWorks\Core::$appDirs, [$directory]); $this->assertEquals($expected, $this->config->getConfigPaths()); } }