/** * Copy the Envariable config template to the application config. * * @param string $applicationConfigDirectoryPath */ public function createConfigFile($applicationConfigDirectoryPath) { $envariableConfigDirectoryPath = sprintf('%s%sEnvariable', $applicationConfigDirectoryPath, DIRECTORY_SEPARATOR); if (!$this->filesystem->createDirectory($envariableConfigDirectoryPath)) { throw new \RuntimeException('Could not create Envariable config directory.'); } $configTemplatePath = sprintf('Config%sConfigTemplate.php', DIRECTORY_SEPARATOR); $envariableConfigFilePath = sprintf('%s%sconfig.php', $envariableConfigDirectoryPath, DIRECTORY_SEPARATOR); if (!$this->filesystem->copyFile($configTemplatePath, $envariableConfigFilePath)) { throw new \RuntimeException('Could not copy config file to destination.'); } }
/** * Test that it throws an exception as it fails to copy the config template file to its destination. * * @param \Envariable\Util\Filesystem $filesystem */ function it_throws_exception_could_not_copy_config_file_to_destination(Filesystem $filesystem) { $applicationConfigDirectoryPath = 'path/to/application/config'; $envariableConfigDirectoryPath = $applicationConfigDirectoryPath . '/Envariable'; $configTemplatePath = 'Config/ConfigTemplate.php'; $envariableConfigFilePath = $envariableConfigDirectoryPath . '/config.php'; $filesystem->createDirectory($envariableConfigDirectoryPath)->willReturn(true); $filesystem->copyFile($configTemplatePath, $envariableConfigFilePath)->willReturn(false); $this->setFilesystem($filesystem); $this->shouldThrow(new \RuntimeException('Could not copy config file to destination.'))->duringCreateConfigFile($applicationConfigDirectoryPath); }