Skip to content

Commit cc004ed

Browse files
committed
Merge branch '4.1'
* 4.1: [Console] simplified code removed useless phpdoc improve docblocks around group sequences [Cache] prevent getting older entries when the version key is evicted [WebProfilerBundle] added a note in the README [Yaml] Skip parser test with root user [Filesystem] Skip tests on readable file when run with root user [FWBundle] Fix an error in WebTestCase::createClient's PHPDoc [HttpFoundation][Security] forward locale and format to subrequests [Console] Send the right exit code to console.terminate listeners [HttpFoundation] fix hidding warnings from session handlers Caching missed templates on cache warmup
2 parents f7d88a1 + d3dbe91 commit cc004ed

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null
159159
} else {
160160
$exitCode = 1;
161161
}
162+
163+
return $exitCode;
162164
} finally {
163165
// if the exception handler changed, keep it
164166
// otherwise, unregister $renderException

Tests/ApplicationTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,31 @@ public function testRunReturnsIntegerExitCode()
985985
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
986986
}
987987

988+
public function testRunDispatchesIntegerExitCode()
989+
{
990+
$passedRightValue = false;
991+
992+
// We can assume here that some other test asserts that the event is dispatched at all
993+
$dispatcher = new EventDispatcher();
994+
$self = $this;
995+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
996+
$passedRightValue = (4 === $event->getExitCode());
997+
});
998+
999+
$application = new Application();
1000+
$application->setDispatcher($dispatcher);
1001+
$application->setAutoExit(false);
1002+
1003+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
1004+
throw new \Exception('', 4);
1005+
});
1006+
1007+
$tester = new ApplicationTester($application);
1008+
$tester->run(array('command' => 'test'));
1009+
1010+
$this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
1011+
}
1012+
9881013
public function testRunReturnsExitCodeOneForExceptionCodeZero()
9891014
{
9901015
$exception = new \Exception('', 0);
@@ -1000,6 +1025,31 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
10001025
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
10011026
}
10021027

1028+
public function testRunDispatchesExitCodeOneForExceptionCodeZero()
1029+
{
1030+
$passedRightValue = false;
1031+
1032+
// We can assume here that some other test asserts that the event is dispatched at all
1033+
$dispatcher = new EventDispatcher();
1034+
$self = $this;
1035+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
1036+
$passedRightValue = (1 === $event->getExitCode());
1037+
});
1038+
1039+
$application = new Application();
1040+
$application->setDispatcher($dispatcher);
1041+
$application->setAutoExit(false);
1042+
1043+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
1044+
throw new \Exception();
1045+
});
1046+
1047+
$tester = new ApplicationTester($application);
1048+
$tester->run(array('command' => 'test'));
1049+
1050+
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
1051+
}
1052+
10031053
/**
10041054
* @expectedException \LogicException
10051055
* @expectedExceptionMessage An option with shortcut "e" already exists.

0 commit comments

Comments
 (0)