merged branch Tobion/console-exit-code (PR #8080)
This PR was merged into the 2.1 branch.
Discussion
----------
[Console] fix and refactor exit code handling
Split of #8038
Commits
-------
5c317b7
[Console] fix and refactor exit code handling
This commit is contained in:
commit
92399ff79a
|
@ -115,7 +115,7 @@ class Application
|
|||
}
|
||||
$statusCode = $e->getCode();
|
||||
|
||||
$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1;
|
||||
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
|
||||
}
|
||||
|
||||
if ($this->autoExit) {
|
||||
|
@ -192,7 +192,7 @@ class Application
|
|||
$statusCode = $command->run($input, $output);
|
||||
$this->runningCommand = null;
|
||||
|
||||
return is_numeric($statusCode) ? $statusCode : 0;
|
||||
return $statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -238,7 +238,7 @@ class Command
|
|||
$statusCode = $this->execute($input, $output);
|
||||
}
|
||||
|
||||
return is_numeric($statusCode) ? $statusCode : 0;
|
||||
return is_numeric($statusCode) ? (int) $statusCode : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -501,6 +501,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
|
||||
}
|
||||
|
||||
public function testRunReturnsIntegerExitCode()
|
||||
{
|
||||
$exception = new \Exception('', 4);
|
||||
|
||||
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
|
||||
$application->setAutoExit(false);
|
||||
$application->expects($this->once())
|
||||
->method('doRun')
|
||||
->will($this->throwException($exception));
|
||||
|
||||
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
|
||||
|
||||
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @dataProvider getAddingAlreadySetDefinitionElementData
|
||||
|
|
|
@ -221,6 +221,20 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public function testRunReturnsIntegerExitCode()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$exitCode = $command->run(new StringInput(''), new NullOutput());
|
||||
$this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)');
|
||||
|
||||
$command = $this->getMock('TestCommand', array('execute'));
|
||||
$command->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue('2.3'));
|
||||
$exitCode = $command->run(new StringInput(''), new NullOutput());
|
||||
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
|
||||
}
|
||||
|
||||
public function testRunReturnsAlwaysInteger()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
|
|
Reference in New Issue