php - Testing Symfony2 Console Commands that expect input -


i trying test symfony2 console command using phpunit.

i'm following symfony2 cookbook article topic: http://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input

however, if fail provide input (a test fail), phpunit sit there doing nothing waiting input. here's example:

// mycommand.php class mycommand extends command {   // ... configure()    protected function execute(inputinterface $input, outputinterface $output) {      $qh = $this->gethelper('question');      $q1 = new confirmationquestion('first question, yes or no?', false);      $qh->ask($input, $output, $q);      $q2 = new confirmationquestion('second question, yes or no?', false);      $qh->ask($input, $output, $q);   } }  // mycommandtest.php class mycommandtest extends \phpunit_framework_testcase {   // ... getinputstream()    public function testexecute() {     $app = new application();     $app->add(new mycommand());      $cmd = $app->find('askquestions');     $cmdtester = new commandtester($cmd);      $helper = $cmd->gethelper('question');     $helper->setinputstream($this->getinputstream('y\\n')); // should yy\\n      $cmdtester->execute([        'command' => $cmd->getname(),     ]);   } } 

please notice have purposefully made test incorrect, supplying answer question 1. since wrote test, have since added q2 forgot modify tests. being programmer though run phpunit see if there problems, phpunit hangs expects input q2!

how make test disregard further requests input, fail if encounters one, , keep going other tests?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -