From 491811011cd73e15b969ce8779acb6589dd72779 Mon Sep 17 00:00:00 2001 From: Vasek Purchart Date: Wed, 27 Jan 2016 12:18:05 +0100 Subject: [PATCH 1/2] fix CS issues in Console Application and ApplicationTest --- src/Symfony/Component/Console/Application.php | 4 ++-- src/Symfony/Component/Console/Tests/ApplicationTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 11ac33378f712..3651069fc3fc6 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -717,7 +717,7 @@ public function renderException($e, $output) 'args' => array(), )); - for ($i = 0, $count = count($trace); $i < $count; $i++) { + for ($i = 0, $count = count($trace); $i < $count; ++$i) { $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; $function = $trace[$i]['function']; @@ -1086,7 +1086,7 @@ private function findAlternatives($name, $collection) } } - $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2*$threshold; }); + $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; }); asort($alternatives); return array_keys($alternatives); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 1fa6c64af6501..1aae0f9ffe3b6 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -679,7 +679,7 @@ public function testRun() } /** - * Issue #9285 + * Issue #9285. * * If the "verbose" option is just before an argument in ArgvInput, * an argument value should not be treated as verbosity value. From 4862ed39dc07611c0e07a5eb86030048c6a2e77e Mon Sep 17 00:00:00 2001 From: Vasek Purchart Date: Thu, 9 Apr 2015 16:52:37 +0200 Subject: [PATCH 2/2] [Console] Add getters for Application::$autoExit and $catchExceptions --- src/Symfony/Component/Console/Application.php | 20 +++++++++++++++++++ .../Console/Tests/ApplicationTest.php | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 3651069fc3fc6..65cae45020fd7 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -254,6 +254,16 @@ public function getHelp() return $this->getLongVersion(); } + /** + * Gets whether to catch exceptions or not during commands execution. + * + * @return bool Whether to catch exceptions or not during commands execution + */ + public function areExceptionsCaught() + { + return $this->catchExceptions; + } + /** * Sets whether to catch exceptions or not during commands execution. * @@ -266,6 +276,16 @@ public function setCatchExceptions($boolean) $this->catchExceptions = (bool) $boolean; } + /** + * Gets whether to automatically exit after a command execution or not. + * + * @return bool Whether to automatically exit after a command execution or not + */ + public function isAutoExitEnabled() + { + return $this->autoExit; + } + /** * Sets whether to automatically exit after a command execution or not. * diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 1aae0f9ffe3b6..f65adf9452d46 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -477,6 +477,7 @@ public function testSetCatchExceptions() $tester = new ApplicationTester($application); $application->setCatchExceptions(true); + $this->assertTrue($application->areExceptionsCaught()); $tester->run(array('command' => 'foo'), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag'); @@ -490,6 +491,15 @@ public function testSetCatchExceptions() } } + public function testAutoExitSetting() + { + $application = new Application(); + $this->assertTrue($application->isAutoExitEnabled()); + + $application->setAutoExit(false); + $this->assertFalse($application->isAutoExitEnabled()); + } + /** * @group legacy */