10000 Merge branch '2.1' into 2.2 · symfony/symfony@f213a85 · GitHub
[go: up one dir, main page]

Skip to content

Commit f213a85

Browse files
committed
Merge branch '2.1' into 2.2
* 2.1: [Console] fix and refactor exit code handling
2 parents 7b5e680 + 92399ff commit f213a85

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
116116
}
117117
$statusCode = $e->getCode();
118118

119-
$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1;
119+
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
120120
}
121121

122122
if ($this->autoExit) {
@@ -193,7 +193,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
193193
$statusCode = $command->run($input, $output);
194194
$this->runningCommand = null;
195195

196-
return is_numeric($statusCode) ? $statusCode : 0;
196+
return $statusCode;
197197
}
198198

199199
/**

src/Symfony/Component/Console/Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function run(InputInterface $input, OutputInterface $output)
242242
$statusCode = $this->execute($input, $output);
243243
}
244244

245-
return is_numeric($statusCode) ? $statusCode : 0;
245+
return is_numeric($statusCode) ? (int) $statusCode : 0;
246246
}
247247

248248
/**

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,21 @@ public function testRun()
514514
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
515515
}
516516

517+
public function testRunReturnsIntegerExitCode()
518+
{
519+
$exception = new \Exception('', 4);
520+
521+
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
522+
$application->setAutoExit(false);
523+
$application->expects($this->once())
524+
->method('doRun')
525+
->will($this->throwException($exception));
526+
527+
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
528+
529+
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
530+
}
531+
517532
/**
518533
* @expectedException \LogicException
519534
* @dataProvider getAddingAlreadySetDefinitionElementData

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ public function testRun()
244244
}
245245
}
246246

247+
public function testRunReturnsIntegerExitCode()
248+
{
249+
$command = new \TestCommand();
250+
$exitCode = $command->run(new StringInput(''), new NullOutput());
251+
$this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)');
252+
253+
$command = $this->getMock('TestCommand', array('execute'));
254+
$command->expects($this->once())
255+
->method('execute')
256+
->will($this->returnValue('2.3'));
257+
$exitCode = $command->run(new StringInput(''), new NullOutput());
258+
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
259+
}
260+
247261
public function testRunReturnsAlwaysInteger()
248262
{
249263
$command = new \TestCommand();

0 commit comments

Comments
 (0)
0