diff --git a/module/CLI/test/Install/Plugin/LanguageConfigCustomizerPluginTest.php b/module/CLI/test/Install/Plugin/LanguageConfigCustomizerPluginTest.php index 44d82cb4..0edc382e 100644 --- a/module/CLI/test/Install/Plugin/LanguageConfigCustomizerPluginTest.php +++ b/module/CLI/test/Install/Plugin/LanguageConfigCustomizerPluginTest.php @@ -83,7 +83,6 @@ class LanguageConfigCustomizerPluginTest extends TestCase /** @var MethodProphecy $ask */ $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); - $config = new CustomizableAppConfig(); $config->setLanguage([ 'DEFAULT' => 'es', diff --git a/module/CLI/test/Install/Plugin/UrlShortenerConfigCustomizerPluginTest.php b/module/CLI/test/Install/Plugin/UrlShortenerConfigCustomizerPluginTest.php new file mode 100644 index 00000000..dc2a9f6e --- /dev/null +++ b/module/CLI/test/Install/Plugin/UrlShortenerConfigCustomizerPluginTest.php @@ -0,0 +1,105 @@ +questionHelper = $this->prophesize(QuestionHelper::class); + $this->plugin = new UrlShortenerConfigCustomizerPlugin($this->questionHelper->reveal()); + } + + /** + * @test + */ + public function configIsRequestedToTheUser() + { + /** @var MethodProphecy $askSecret */ + $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('something'); + $config = new CustomizableAppConfig(); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertTrue($config->hasUrlShortener()); + $this->assertEquals([ + 'SCHEMA' => 'something', + 'HOSTNAME' => 'something', + 'CHARS' => 'something', + ], $config->getUrlShortener()); + $askSecret->shouldHaveBeenCalledTimes(3); + } + + /** + * @test + */ + public function overwriteIsRequestedIfValueIsAlreadySet() + { + /** @var MethodProphecy $ask */ + $ask = $this->questionHelper->ask(Argument::cetera())->will(function (array $args) { + $last = array_pop($args); + return $last instanceof ConfirmationQuestion ? false : 'foo'; + }); + $config = new CustomizableAppConfig(); + $config->setUrlShortener([ + 'SCHEMA' => 'bar', + 'HOSTNAME' => 'bar', + 'CHARS' => 'bar', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'SCHEMA' => 'foo', + 'HOSTNAME' => 'foo', + 'CHARS' => 'foo', + ], $config->getUrlShortener()); + $ask->shouldHaveBeenCalledTimes(4); + } + + /** + * @test + */ + public function existingValueIsKeptIfRequested() + { + /** @var MethodProphecy $ask */ + $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); + + $config = new CustomizableAppConfig(); + $config->setUrlShortener([ + 'SCHEMA' => 'foo', + 'HOSTNAME' => 'foo', + 'CHARS' => 'foo', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'SCHEMA' => 'foo', + 'HOSTNAME' => 'foo', + 'CHARS' => 'foo', + ], $config->getUrlShortener()); + $ask->shouldHaveBeenCalledTimes(1); + } +}