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('error')); } /** * @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', Priority::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', Priority::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()); } /** * @depends testLoadConfigOverride * @covers \FuzeWorks\Config::overrideConfig * @covers \FuzeWorks\Config::loadConfigFile */ public function testLoadConfigCoreOverride() { // First see that it does not exist $this->assertFalse(isset($this->config->getConfig('error')->toArray()['someKey'])); // Then discard to reset the test $this->config->discardConfigFiles(); // Create the override Config::overrideConfig('error', 'someKey', 'someValue'); // And test that it exists now $this->assertTrue(isset($this->config->getConfig('error')->toArray()['someKey'])); $this->assertEquals('someValue', $this->config->getConfig('error')->toArray()['someKey']); } /** * @expectedException FuzeWorks\Exception\ConfigException */ public function testAddComponentPathFail() { // Now test if the config can be loaded (hint: it can not) $this->config->getConfig('testAddComponentPath'); } /** * @depends testAddComponentPathFail */ public function testaddComponentPath() { // Add the configPath $this->config->addComponentPath('test'.DS.'config'.DS.'TestAddComponentPath'); // And try to load it again $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('testAddComponentPath')); } public function testremoveComponentPath() { // Test if the path does NOT exist $this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); // Add it $this->config->addComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath'); // Assert if it's there $this->assertTrue(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); // Remove it $this->config->removeComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath'); // And test if it's gone again $this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); } 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->getComponentPaths()); } }