Skip to content

Commit d3dbe91

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: [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 d7d1b29 + 1cbaac3 commit d3dbe91

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
@@ -960,6 +960,31 @@ public function testRunReturnsIntegerExitCode()
960960
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
961961
}
962962

963+
public function testRunDispatchesIntegerExitCode()
964+
{
965+
$passedRightValue = false;
966+
967+
// We can assume here that some other test asserts that the event is dispatched at all
968+
$dispatcher = new EventDispatcher();
969+
$self = $this;
970+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
971+
$passedRightValue = (4 === $event->getExitCode());
972+
});
973+
974+
$application = new Application();
975+
$application->setDispatcher($dispatcher);
976+
$application->setAutoExit(false);
977+
978+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
979+
throw new \Exception('', 4);
980+
});
981+
982+
$tester = new ApplicationTester($application);
983+
$tester->run(array('command' => 'test'));
984+
985+
$this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
986+
}
987+
963988
public function testRunReturnsExitCodeOneForExceptionCodeZero()
964989
{
965990
$exception = new \Exception('', 0);
@@ -975,6 +1000,31 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
9751000
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
9761001
}
9771002

1003+
public function testRunDispatchesExitCodeOneForExceptionCodeZero()
1004+
{
1005+
$passedRightValue = false;
1006+
1007+
// We can assume here that some other test asserts that the event is dispatched at all
1008+
$dispatcher = new EventDispatcher();
1009+
$self = $this;
1010+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
1011+
$passedRightValue = (1 === $event->getExitCode());
1012+
});
1013+
1014+
$application = new Application();
1015+
$application->setDispatcher($dispatcher);
1016+
$application->setAutoExit(false);
1017+
1018+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
1019+
throw new \Exception();
1020+
});
1021+
1022+
$tester = new ApplicationTester($application);
1023+
$tester->run(array('command' => 'test'));
1024+
1025+
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
1026+
}
1027+
9781028
/**
9791029
* @expectedException \LogicException
9801030
* @expectedExceptionMessage An option with shortcut "e" already exists.

0 commit comments

Comments
 (0)