Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Process] added exit code to ProcessFailedException message
  • Loading branch information
zakharovvi committed Apr 11, 2013
1 parent cb6bbfb commit fb7625f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Exception/ProcessFailedException.php
Expand Up @@ -30,8 +30,10 @@ public function __construct(Process $process)

parent::__construct(
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->getExitCode(),
$process->getExitCodeText(),
$process->getOutput(),
$process->getErrorOutput()
)
Expand Down
12 changes: 10 additions & 2 deletions Tests/ProcessFailedExceptionTest.php
Expand Up @@ -46,12 +46,14 @@ public function testProcessFailedExceptionThrowsException()
public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
{
$cmd = 'php';
$exitCode = 1;
$exitText = 'General error';
$output = "Command output";
$errorOutput = "FATAL: Unexpected error";

$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'getOutput', 'getErrorOutput'),
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText'),
array($cmd)
);
$process->expects($this->once())
Expand All @@ -63,11 +65,17 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
$process->expects($this->once())
->method('getErrorOutput')
->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);

$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()
);
}
Expand Down

0 comments on commit fb7625f

Please sign in to comment.