From 6526166b05674976bb1deb42b1c3ca9342856e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 13 May 2013 09:35:44 +0200 Subject: [PATCH] [Console] Added status code to CommandTester and ApplicationTester Theses classes are already statefull. They contain the input and the output data. So we can safely add the last status code to the class. --- .../Component/Console/Tester/ApplicationTester.php | 13 ++++++++++++- .../Component/Console/Tester/CommandTester.php | 13 ++++++++++++- .../Console/Tests/Tester/ApplicationTesterTest.php | 5 +++++ .../Console/Tests/Tester/CommandTesterTest.php | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Tester/ApplicationTester.php b/src/Symfony/Component/Console/Tester/ApplicationTester.php index 2e57e1a35d..dd7c2a5dc0 100644 --- a/src/Symfony/Component/Console/Tester/ApplicationTester.php +++ b/src/Symfony/Component/Console/Tester/ApplicationTester.php @@ -32,6 +32,7 @@ class ApplicationTester private $application; private $input; private $output; + private $statusCode; /** * Constructor. @@ -72,7 +73,7 @@ class ApplicationTester $this->output->setVerbosity($options['verbosity']); } - return $this->application->run($this->input, $this->output); + return $this->statusCode = $this->application->run($this->input, $this->output); } /** @@ -114,4 +115,14 @@ class ApplicationTester { return $this->output; } + + /** + * Gets the status code returned by the last execution of the application. + * + * @return integer The status code + */ + public function getStatusCode() + { + return $this->statusCode; + } } diff --git a/src/Symfony/Component/Console/Tester/CommandTester.php b/src/Symfony/Component/Console/Tester/CommandTester.php index 23dae245d3..3d91aaff65 100644 --- a/src/Symfony/Component/Console/Tester/CommandTester.php +++ b/src/Symfony/Component/Console/Tester/CommandTester.php @@ -25,6 +25,7 @@ class CommandTester private $command; private $input; private $output; + private $statusCode; /** * Constructor. @@ -65,7 +66,7 @@ class CommandTester $this->output->setVerbosity($options['verbosity']); } - return $this->command->run($this->input, $this->output); + return $this->statusCode = $this->command->run($this->input, $this->output); } /** @@ -107,4 +108,14 @@ class CommandTester { return $this->output; } + + /** + * Gets the status code returned by the last execution of the application. + * + * @return integer The status code + */ + public function getStatusCode() + { + return $this->statusCode; + } } diff --git a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php index 6ce30ab0fc..a8389dd186 100644 --- a/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php @@ -61,4 +61,9 @@ class ApplicationTesterTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); } + + public function testGetStatusCode() + { + $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code'); + } } diff --git a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php index da5bf84e22..1067e9ffc6 100644 --- a/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php +++ b/src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php @@ -59,4 +59,9 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); } + + public function testGetStatusCode() + { + $this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code'); + } }