config = new Config(); } /** * @coversNothing */ public function testGetConfigClass() { $this->assertInstanceOf('FuzeWorks\Config', $this->config); } /** * @depends testGetConfigClass * @covers ::getConfig * @covers ::loadConfigFile */ public function testLoadConfig() { $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('error')); } /** * @depends testLoadConfig * @covers ::getConfig * @covers ::loadConfigFile */ public function testLoadConfigWithAltDirectory() { $config = $this->config->getConfig('TestLoadConfigWithAltDirectory', ['test'.DS.'config'.DS.'TestLoadConfigWithAltDirectory'.DS.'SubDirectory']); $this->assertEquals('value', $config->key); } /** * @depends testLoadConfig * @covers ::loadConfigFile */ public function testFileNotFound() { $this->expectException(ConfigException::class); $this->config->getConfig('notFound'); } /** * @depends testLoadConfig * @covers ::loadConfigFile */ 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 * @covers ::loadConfigFile */ 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 ::overrideConfig * @covers ::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 ::overrideConfig * @covers ::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']); } /** * @covers ::getConfig */ 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('value', $config->key); // Change it and test if it's different now $config->key = 'other_value'; $this->assertEquals('other_value', $config2->key); } /** * @coversNothing */ public function testConfigWithEnvironmentVariables() { // First push the test variable putenv('TESTKEY=Superb'); // Load the config $config = $this->config->getConfig('testconfigwithenvironment', ['test'.DS.'config'.DS.'TestConfigWithEnvironment']); // Check values $this->assertEquals('Superb', $config->get('testKey')); $this->assertEquals('somethingDefault', $config->get('otherKey')); } }