From a66f116d664987a90b3dcb4e597cf10b4a26003a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 6 Jul 2017 18:00:38 +0200 Subject: [PATCH] Created DatabaseConfigCustomizerPluginTest --- .../ApplicationConfigCustomizerPluginTest.php | 1 - .../DatabaseConfigCustomizerPluginTest.php | 152 ++++++++++++++++++ 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 module/CLI/test/Install/Plugin/DatabaseConfigCustomizerPluginTest.php diff --git a/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php index d0a4505d..2b30a328 100644 --- a/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php +++ b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerPluginTest.php @@ -78,7 +78,6 @@ class ApplicationConfigCustomizerPluginTest extends TestCase /** @var MethodProphecy $ask */ $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); - $config = new CustomizableAppConfig(); $config->setApp([ 'SECRET' => 'foo', diff --git a/module/CLI/test/Install/Plugin/DatabaseConfigCustomizerPluginTest.php b/module/CLI/test/Install/Plugin/DatabaseConfigCustomizerPluginTest.php new file mode 100644 index 00000000..85d18225 --- /dev/null +++ b/module/CLI/test/Install/Plugin/DatabaseConfigCustomizerPluginTest.php @@ -0,0 +1,152 @@ +questionHelper = $this->prophesize(QuestionHelper::class); + $this->filesystem = $this->prophesize(Filesystem::class); + + $this->plugin = new DatabaseConfigCustomizerPlugin( + $this->questionHelper->reveal(), + $this->filesystem->reveal() + ); + } + + /** + * @test + */ + public function configIsRequestedToTheUser() + { + /** @var MethodProphecy $askSecret */ + $askSecret = $this->questionHelper->ask(Argument::cetera())->willReturn('MySQL'); + $config = new CustomizableAppConfig(); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertTrue($config->hasDatabase()); + $this->assertEquals([ + 'DRIVER' => 'pdo_mysql', + 'NAME' => 'MySQL', + 'USER' => 'MySQL', + 'PASSWORD' => 'MySQL', + 'HOST' => 'MySQL', + 'PORT' => 'MySQL', + ], $config->getDatabase()); + $askSecret->shouldHaveBeenCalledTimes(6); + } + + /** + * @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 : 'MySQL'; + }); + $config = new CustomizableAppConfig(); + $config->setDatabase([ + 'DRIVER' => 'pdo_pgsql', + 'NAME' => 'MySQL', + 'USER' => 'MySQL', + 'PASSWORD' => 'MySQL', + 'HOST' => 'MySQL', + 'PORT' => 'MySQL', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'DRIVER' => 'pdo_mysql', + 'NAME' => 'MySQL', + 'USER' => 'MySQL', + 'PASSWORD' => 'MySQL', + 'HOST' => 'MySQL', + 'PORT' => 'MySQL', + ], $config->getDatabase()); + $ask->shouldHaveBeenCalledTimes(7); + } + + /** + * @test + */ + public function existingValueIsKeptIfRequested() + { + /** @var MethodProphecy $ask */ + $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); + + $config = new CustomizableAppConfig(); + $config->setDatabase([ + 'DRIVER' => 'pdo_pgsql', + 'NAME' => 'MySQL', + 'USER' => 'MySQL', + 'PASSWORD' => 'MySQL', + 'HOST' => 'MySQL', + 'PORT' => 'MySQL', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'DRIVER' => 'pdo_pgsql', + 'NAME' => 'MySQL', + 'USER' => 'MySQL', + 'PASSWORD' => 'MySQL', + 'HOST' => 'MySQL', + 'PORT' => 'MySQL', + ], $config->getDatabase()); + $ask->shouldHaveBeenCalledTimes(1); + } + + /** + * @test + */ + public function sqliteDatabaseIsImportedWhenRequested() + { + /** @var MethodProphecy $ask */ + $ask = $this->questionHelper->ask(Argument::cetera())->willReturn(true); + /** @var MethodProphecy $copy */ + $copy = $this->filesystem->copy(Argument::cetera())->willReturn(null); + + $config = new CustomizableAppConfig(); + $config->setDatabase([ + 'DRIVER' => 'pdo_sqlite', + ]); + + $this->plugin->process(new ArrayInput([]), new NullOutput(), $config); + + $this->assertEquals([ + 'DRIVER' => 'pdo_sqlite', + ], $config->getDatabase()); + $ask->shouldHaveBeenCalledTimes(1); + $copy->shouldHaveBeenCalledTimes(1); + } +}