Skip to content

Commit

Permalink
Test second question in AddProjectsCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
juanber84 committed May 30, 2016
1 parent 0b16fc4 commit 755b65a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Juanber84/Console/Command/AddProjectsCommand.php
Expand Up @@ -53,8 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$helper->ask($input, $output, $question)) {
return $output->writeln("<fg=blue;>".AddProjectsCommandText::KO_ABORTED.'</>');
}

$jsonDb = $this->databaseService->getProjects();

if (array_key_exists($nameOfProject,$jsonDb)) {
$question = new ConfirmationQuestion('<error>This project exist. Do you want override it?</error> <info>Y/n</info> ', false);
if (!$helper->ask($input, $output, $question)) {
Expand Down
31 changes: 29 additions & 2 deletions tests/Console/Command/AddProjectsCommandTest.php
Expand Up @@ -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')
Expand All @@ -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;
}

Expand Down

0 comments on commit 755b65a

Please sign in to comment.