From 1213d368f67cd802d6ac659272a3aeba6ebed35b Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Thu, 30 Apr 2015 12:16:18 +0200 Subject: [PATCH] Updated tests for new QuestionHelper flow --- tests/Composer/Test/IO/ConsoleIOTest.php | 89 ++++++++++++++---------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index d0af8cb42..a61b310da 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -129,20 +129,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) + $helperMock + ->expects($this->once()) ->method('ask') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('default')); - $helperMock->expects($this->once()) - ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\Question') + ) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $setMock + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; + + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->ask('Why?', 'default'); } @@ -150,20 +157,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) - ->method('askConfirmation') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('default')); - $helperMock->expects($this->once()) + $helperMock + ->expects($this->once()) + ->method('ask') + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\ConfirmationQuestion') + ) + ; + + $setMock + ->expects($this->once()) ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->askConfirmation('Why?', 'default'); } @@ -171,22 +185,27 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper'); - $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); + $helperMock = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper'); + $setMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); - $dialogMock->expects($this->once()) - ->method('askAndValidate') - ->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), - $this->equalTo('Why?'), - $this->equalTo('validator'), - $this->equalTo(10), - $this->equalTo('default')); - $helperMock->expects($this->once()) + $helperMock + ->expects($this->once()) + ->method('ask') + ->with( + $this->isInstanceOf('Symfony\Component\Console\Input\InputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'), + $this->isInstanceOf('Symfony\Component\Console\Question\Question') + ) + ; + + $setMock + ->expects($this->once()) ->method('get') - ->with($this->equalTo('dialog')) - ->will($this->returnValue($dialogMock)); + ->with($this->equalTo('question')) + ->will($this->returnValue($helperMock)) + ; - $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); + $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->askAndValidate('Why?', 'validator', 10, 'default'); }