From 755b65a0bc79a41e09c4d78dd821a3f203819b5c Mon Sep 17 00:00:00 2001 From: juanber84 Date: Mon, 30 May 2016 13:12:46 +0200 Subject: [PATCH] Test second question in AddProjectsCommand --- .../Console/Command/AddProjectsCommand.php | 2 +- .../Command/AddProjectsCommandTest.php | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Juanber84/Console/Command/AddProjectsCommand.php b/src/Juanber84/Console/Command/AddProjectsCommand.php index c15f658..669c0a8 100644 --- a/src/Juanber84/Console/Command/AddProjectsCommand.php +++ b/src/Juanber84/Console/Command/AddProjectsCommand.php @@ -53,8 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$helper->ask($input, $output, $question)) { return $output->writeln("".AddProjectsCommandText::KO_ABORTED.''); } - $jsonDb = $this->databaseService->getProjects(); + if (array_key_exists($nameOfProject,$jsonDb)) { $question = new ConfirmationQuestion('This project exist. Do you want override it? Y/n ', false); if (!$helper->ask($input, $output, $question)) { diff --git a/tests/Console/Command/AddProjectsCommandTest.php b/tests/Console/Command/AddProjectsCommandTest.php index f9c5c50..e791429 100644 --- a/tests/Console/Command/AddProjectsCommandTest.php +++ b/tests/Console/Command/AddProjectsCommandTest.php @@ -65,6 +65,25 @@ public function testYesQuestionsDatabaseReturnFalse() $this->assertRegExp('/'.AddProjectsCommandText::KO_ERROR.'/', $commandTester->getDisplay()); } + public function testYesQuestionsSecondTruQuestionDatabaseReturnFalse() + { + $questionNameProject = $this->getMockQuestionConfirmHelper(true,false); + $databaseService = $this->getMockDatabaseService(array('fake'=>'/'), false); + + $application = new Application(); + $application->add(new AddProjectsCommand($databaseService)); + + $command = $application->find(AddProjectsCommand::COMMAND_NAME); + $command->getHelperSet()->set($questionNameProject, 'question'); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + 'command' => $command->getName(), + 'project' => 'fake' + )); + + $this->assertRegExp('/'.AddProjectsCommandText::KO_ABORTED.'/', $commandTester->getDisplay()); + } + private function getMockDatabaseService($valueReturnGetProjects, $valueReturnRemoveProject = null) { $applicationService = $this->getMockBuilder('Juanber84\Services\DatabaseService') @@ -79,13 +98,21 @@ private function getMockDatabaseService($valueReturnGetProjects, $valueReturnRem return $applicationService; } - private function getMockQuestionConfirmHelper($valueReturn) + private function getMockQuestionConfirmHelper($valueReturn, $secondeValueReturn = null) { $question = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper', array('ask')); - $question->expects($this->at(0)) + $question + ->expects($this->at(0)) ->method('ask') ->will($this->returnValue($valueReturn)); + if ($secondeValueReturn){ + $question + ->expects($this->at(1)) + ->method('ask') + ->will($this->returnValue($secondeValueReturn)); + } + return $question; }