From d56cde72a380c1945e294e9d2df3f8d9b42adaa6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 6 Jul 2017 17:12:19 +0200 Subject: [PATCH] Created ApplicationConfigCustomizerPluginTest --- .../ApplicationConfigCustomizerPluginTest.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php diff --git a/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php new file mode 100644 index 00000000..cd4cef42 --- /dev/null +++ b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php @@ -0,0 +1,96 @@ +questionHelper = $this->prophesize(QuestionHelper::class); + $this->plugin = new ApplicationConfigCustomizerPlugin($this->questionHelper->reveal()); + } + + /** + * @test + */ + public function configIsRequestedToTheUser() + { + /** @var MethodProphecy $askSecret */ + $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('the_secret'); + $config = new CustomizableAppConfig(); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertTrue($config->hasApp()); + $this->assertEquals([ + 'SECRET' => 'the_secret', + ], $config->getApp()); + $askSecret->shouldHaveBeenCalledTimes(1); + } + + /** + * @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 : 'the_new_secret'; + }); + $config = new CustomizableAppConfig(); + $config->setApp([ + 'SECRET' => 'foo', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'SECRET' => 'the_new_secret', + ], $config->getApp()); + $ask->shouldHaveBeenCalledTimes(2); + } + + /** + * @test + */ + public function existingValueIsKeptIfRequested() + { + /** @var MethodProphecy $ask */ + $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); + + + $config = new CustomizableAppConfig(); + $config->setApp([ + 'SECRET' => 'foo', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'SECRET' => 'foo', + ], $config->getApp()); + $ask->shouldHaveBeenCalledTimes(1); + } +}