浏览代码

[Console] changed returned value of CommandTester to the command exit code

Fabien Potencier 14 年之前
父节点
当前提交
ad4a0bda1c

+ 6 - 2
src/Symfony/Component/Console/Tester/CommandTester.php

@@ -46,6 +46,8 @@ class CommandTester
      *
      * @param array $input   An array of arguments and options
      * @param array $options An array of options
+     *
+     * @return integer The command exit code
      */
     public function execute(array $input, array $options = array())
     {
@@ -62,11 +64,13 @@ class CommandTester
             $this->output->setVerbosity($options['verbosity']);
         }
 
-        $this->command->run($this->input, $this->output);
+        $code = $this->command->run($this->input, $this->output);
 
         rewind($this->output->getStream());
 
-        return $this->display = stream_get_contents($this->output->getStream());
+        $this->display = stream_get_contents($this->output->getStream());
+
+        return $code;
     }
 
     /**

+ 5 - 2
tests/Symfony/Tests/Component/Console/Command/CommandTest.php

@@ -205,8 +205,11 @@ class CommandTest extends \PHPUnit_Framework_TestCase
             $this->assertEquals('The "--bar" option does not exist.', $e->getMessage(), '->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
         }
 
-        $this->assertEquals('interact called'.PHP_EOL.'execute called'.PHP_EOL, $tester->execute(array(), array('interactive' => true)), '->run() calls the interact() method if the input is interactive');
-        $this->assertEquals('execute called'.PHP_EOL, $tester->execute(array(), array('interactive' => false)), '->run() does not call the interact() method if the input is not interactive');
+        $tester->execute(array(), array('interactive' => true));
+        $this->assertEquals('interact called'.PHP_EOL.'execute called'.PHP_EOL, $tester->getDisplay(), '->run() calls the interact() method if the input is interactive');
+
+        $tester->execute(array(), array('interactive' => false));
+        $this->assertEquals('execute called'.PHP_EOL, $tester->getDisplay(), '->run() does not call the interact() method if the input is not interactive');
 
         $command = new Command('foo');
         try {