fileManager = new ConfigFileManager; /*copy defaultTestConfig file to cache*/ if (!file_exists($this->configPath)) { copy($this->defaultTestConfig, $this->configPath); } $this->config = new Config($this->fileManager); $this->reflection = new ReflectionHelper($this->config); $this->reflection->setProperty('configPath', $this->configPath); $this->reflection->setProperty('systemConfigPath', $this->systemConfigPath); } protected function tearDown() : void { $this->config = NULL; } public function testLoadConfig() { $this->assertArrayHasKey('database', $this->reflection->invokeMethod('loadConfig', array())); $this->assertArrayHasKey('dateFormat', $this->reflection->invokeMethod('loadConfig', array())); } public function testGet() { $result = array( 'driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'espocrm', 'user' => 'root', 'password' => '', ); $this->assertEquals($result, $this->config->get('database')); $result = 'pdo_mysql'; $this->assertEquals($result, $this->config->get('database.driver')); $result = 'YYYY-MM-DD'; $this->assertEquals($result, $this->config->get('dateFormat')); $this->assertTrue($this->config->get('isInstalled')); } public function testSet() { $setKey= 'testOption'; $setValue= 'Test'; $this->config->set($setKey, $setValue); $this->assertTrue($this->config->save()); $this->assertEquals($setValue, $this->config->get($setKey)); $this->config->set($setKey, 'Another Wrong Value'); $this->assertTrue($this->config->save()); } public function testSetNull() { $setKey= 'testOption'; $setValue= 'Test'; $this->config->set($setKey, $setValue); $this->assertTrue($this->config->save()); $this->assertEquals($setValue, $this->config->get($setKey)); $this->config->set($setKey, null); $this->assertTrue($this->config->save()); $this->assertNull($this->config->get($setKey)); } public function testSetArray() { $values = array( 'testOption' => 'Test', 'testOption2' => 'Test2', ); $this->config->set($values); $this->assertTrue($this->config->save()); $this->assertEquals('Test', $this->config->get('testOption')); $this->assertEquals('Test2', $this->config->get('testOption2')); $wrongArray = array( 'testOption' => 'Another Wrong Value', ); $this->config->set($wrongArray); $this->assertTrue($this->config->save()); } public function testRemove() { $optKey = 'removeOption'; $optValue = 'Test'; $this->config->set($optKey, $optValue); $this->assertTrue($this->config->save()); $this->assertTrue($this->config->remove($optKey)); $this->assertNull($this->config->get($optKey)); } public function testSystemConfigMerge() { $configDataWithoutSystem = $this->fileManager->getPhpContents($this->configPath); $this->assertArrayNotHasKey('systemItems', $configDataWithoutSystem); $this->assertArrayNotHasKey('adminItems', $configDataWithoutSystem); $configData = $this->reflection->invokeMethod('loadConfig', array()); $this->assertArrayHasKey('systemItems', $configData); $this->assertArrayHasKey('adminItems', $configData); } }