merged branch zakharovvi/process_exception_exitcode (PR #7628)

This PR was merged into the master branch.

Discussion
----------

[Process] added exit code to ProcessFailedException message

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        | n/a

Commits
-------

7519fdc [Process] added exit code to ProcessFailedException message
This commit is contained in:
Fabien Potencier 2013-04-12 08:33:25 +02:00
commit 09fd2af1cd
2 changed files with 13 additions and 3 deletions

View File

@ -30,8 +30,10 @@ class ProcessFailedException extends RuntimeException
parent::__construct( parent::__construct(
sprintf( sprintf(
'The command "%s" failed.'."\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", 'The command "%s" failed.'."\nExit Code: %s(%s)\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
$process->getCommandLine(), $process->getCommandLine(),
$process->getExitCode(),
$process->getExitCodeText(),
$process->getOutput(), $process->getOutput(),
$process->getErrorOutput() $process->getErrorOutput()
) )

View File

@ -46,12 +46,14 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
public function testProcessFailedExceptionPopulatesInformationFromProcessOutput() public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
{ {
$cmd = 'php'; $cmd = 'php';
$exitCode = 1;
$exitText = 'General error';
$output = "Command output"; $output = "Command output";
$errorOutput = "FATAL: Unexpected error"; $errorOutput = "FATAL: Unexpected error";
$process = $this->getMock( $process = $this->getMock(
'Symfony\Component\Process\Process', 'Symfony\Component\Process\Process',
array('isSuccessful', 'getOutput', 'getErrorOutput'), array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText'),
array($cmd) array($cmd)
); );
$process->expects($this->once()) $process->expects($this->once())
@ -63,11 +65,17 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
$process->expects($this->once()) $process->expects($this->once())
->method('getErrorOutput') ->method('getErrorOutput')
->will($this->returnValue($errorOutput)); ->will($this->returnValue($errorOutput));
$process->expects($this->once())
->method('getExitCode')
->will($this->returnValue($exitCode));
$process->expects($this->once())
->method('getExitCodeText')
->will($this->returnValue($exitText));
$exception = new ProcessFailedException($process); $exception = new ProcessFailedException($process);
$this->assertEquals( $this->assertEquals(
"The command \"$cmd\" failed.\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}", "The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
$exception->getMessage() $exception->getMessage()
); );
} }