/** * Iterate over framework detection commands to identify an appropriate * Envariable config loader and then load the config. * * @return array * * @throws \RuntimeException */ public function loadConfigFile() { try { array_walk($this->frameworkConfigPathLocatorCommandList, array($this, 'frameworkConfigPathLocatorCallback')); } catch (\RuntimeException $runtimeException) { // Do nothing. Exiting array_walk as soon as a config has been loaded. } if (!$this->filesystem->fileExists($this->configPath)) { throw new \RuntimeException('Could not load Envariable config.'); } $envariableConfigFilePath = sprintf('%s%sEnvariable%sconfig.php', $this->configPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); if (!$this->filesystem->fileExists($envariableConfigFilePath)) { $this->configCreator->createConfigFile($envariableConfigFilePath); } return $this->filesystem->loadConfigFile($envariableConfigFilePath); }
/** * Test that createConfigFile is called as envarible config file path does not exist. * * @param \Envariable\Util\Filesystem $filesystem * @param \Envariable\ConfigCreator $configCreator */ function it_will_call_createConfigFile_as_envariable_config_file_does_not_exist(Filesystem $filesystem, ConfigCreator $configCreator) { for ($i = 0; $i < count(self::$commandList); $i++) { $this->addCommand(self::$commandList[$i]); } $configDirectoryPath = 'path/to/config/directory'; $envariableConfigFilePath = $configDirectoryPath . '/Envariable/config.php'; $expectedResult = array('some-config-key' => 'some-config-value'); $filesystem->fileExists($configDirectoryPath)->willReturn(true); $filesystem->fileExists($envariableConfigFilePath)->willReturn(false); $configCreator->createConfigFile($envariableConfigFilePath)->shouldBeCalled(); $filesystem->loadConfigFile($envariableConfigFilePath)->willReturn($expectedResult); $this->setFilesystem($filesystem); $this->setConfigCreator($configCreator); $this->loadConfigFile()->shouldreturn($expectedResult); }