diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index d6ee3ea2..93de4305 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -158,7 +158,7 @@ class InstallCommand extends Command * @return CustomizableAppConfig * @throws RuntimeException */ - protected function importConfig() + private function importConfig() { $config = new CustomizableAppConfig(); @@ -204,7 +204,7 @@ class InstallCommand extends Command * @return string * @throws RuntimeException */ - protected function ask($text, $default = null, $allowEmpty = false) + private function ask($text, $default = null, $allowEmpty = false) { if ($default !== null) { $text .= ' (defaults to ' . $default . ')'; @@ -227,7 +227,7 @@ class InstallCommand extends Command * @param string $errorMessage * @return bool */ - protected function runCommand($command, $errorMessage) + private function runCommand($command, $errorMessage) { $process = $this->processHelper->run($this->output, $command); if ($process->isSuccessful()) { diff --git a/module/CLI/test-resources/config/params/generated_config.php b/module/CLI/test-resources/config/params/generated_config.php new file mode 100644 index 00000000..881ab67d --- /dev/null +++ b/module/CLI/test-resources/config/params/generated_config.php @@ -0,0 +1,2 @@ +getHelperSet(); $helperSet->set($processHelper->reveal()); $app->setHelperSet($helperSet); - $command = new InstallCommand( + $this->command = new InstallCommand( $this->configWriter->reveal(), $this->filesystem->reveal(), $configCustomizers->reveal() ); - $app->add($command); + $app->add($this->command); - $questionHelper = $command->getHelper('question'); -// $questionHelper->setInputStream($this->createInputStream()); - $this->commandTester = new CommandTester($command); + $this->commandTester = new CommandTester($this->command); } -// protected function createInputStream() -// { -// $stream = fopen('php://memory', 'rb+', false); -// fwrite($stream, <<configWriter->toFile(Argument::any(), Argument::type('array'), false)->shouldBeCalledTimes(1); + $this->commandTester->execute([]); + } - $this->commandTester->execute([ - 'command' => 'shlink:install', + /** + * @test + */ + public function cachedConfigIsDeletedIfExists() + { + /** @var MethodProphecy $appConfigExists */ + $appConfigExists = $this->filesystem->exists('data/cache/app_config.php')->willReturn(true); + /** @var MethodProphecy $appConfigRemove */ + $appConfigRemove = $this->filesystem->remove('data/cache/app_config.php')->willReturn(null); + + $this->commandTester->execute([]); + + $appConfigExists->shouldHaveBeenCalledTimes(1); + $appConfigRemove->shouldHaveBeenCalledTimes(1); + } + + /** + * @test + */ + public function exceptionWhileDeletingCachedConfigCancelsProcess() + { + /** @var MethodProphecy $appConfigExists */ + $appConfigExists = $this->filesystem->exists('data/cache/app_config.php')->willReturn(true); + /** @var MethodProphecy $appConfigRemove */ + $appConfigRemove = $this->filesystem->remove('data/cache/app_config.php')->willThrow(IOException::class); + /** @var MethodProphecy $configToFile */ + $configToFile = $this->configWriter->toFile(Argument::cetera())->willReturn(true); + + $this->commandTester->execute([]); + + $appConfigExists->shouldHaveBeenCalledTimes(1); + $appConfigRemove->shouldHaveBeenCalledTimes(1); + $configToFile->shouldNotHaveBeenCalled(); + } + + /** + * @test + */ + public function whenCommandIsUpdatePreviousConfigCanBeImported() + { + $ref = new \ReflectionObject($this->command); + $prop = $ref->getProperty('isUpdate'); + $prop->setAccessible(true); + $prop->setValue($this->command, true); + + /** @var MethodProphecy $importedConfigExists */ + $importedConfigExists = $this->filesystem->exists( + __DIR__ . '/../../../test-resources/' . InstallCommand::GENERATED_CONFIG_PATH + )->willReturn(true); + + $this->commandTester->setInputs([ + '', + '/foo/bar/wrong_previous_shlink', + '', + __DIR__ . '/../../../test-resources', ]); + $this->commandTester->execute([]); + + $importedConfigExists->shouldHaveBeenCalled(); } }