Merge branch '2.2' into 2.3
* 2.2: [Console] fix and refactor exit code handling Conflicts: src/Symfony/Component/Console/Application.php
This commit is contained in:
commit
aa6a73ae73
@ -131,7 +131,7 @@ class Application
|
|||||||
}
|
}
|
||||||
$exitCode = $e->getCode();
|
$exitCode = $e->getCode();
|
||||||
|
|
||||||
$exitCode = is_numeric($exitCode) && $exitCode ? $exitCode : 1;
|
$exitCode = $exitCode ? (is_numeric($exitCode) ? (int) $exitCode : 1) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->autoExit) {
|
if ($this->autoExit) {
|
||||||
@ -184,7 +184,7 @@ class Application
|
|||||||
$exitCode = $this->doRunCommand($command, $input, $output);
|
$exitCode = $this->doRunCommand($command, $input, $output);
|
||||||
$this->runningCommand = null;
|
$this->runningCommand = null;
|
||||||
|
|
||||||
return is_numeric($exitCode) ? $exitCode : 0;
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,7 +244,7 @@ class Command
|
|||||||
$statusCode = $this->execute($input, $output);
|
$statusCode = $this->execute($input, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_numeric($statusCode) ? $statusCode : 0;
|
return is_numeric($statusCode) ? (int) $statusCode : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -558,6 +558,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
|
$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
|
* @expectedException \LogicException
|
||||||
* @dataProvider getAddingAlreadySetDefinitionElementData
|
* @dataProvider getAddingAlreadySetDefinitionElementData
|
||||||
|
@ -260,6 +260,20 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$tester->execute(array('--bar' => true));
|
$tester->execute(array('--bar' => true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function testRunReturnsAlwaysInteger()
|
||||||
{
|
{
|
||||||
$command = new \TestCommand();
|
$command = new \TestCommand();
|
||||||
|
Reference in New Issue
Block a user