From 7519fdc10fa41b6bfcabda8627f794d05ceff3ad Mon Sep 17 00:00:00 2001 From: Vitaliy Zakharov Date: Thu, 11 Apr 2013 19:44:10 +0600 Subject: [PATCH] [Process] added exit code to ProcessFailedException message --- .../Process/Exception/ProcessFailedException.php | 4 +++- .../Process/Tests/ProcessFailedExceptionTest.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Process/Exception/ProcessFailedException.php b/src/Symfony/Component/Process/Exception/ProcessFailedException.php index 936cbc619c..890935933b 100644 --- a/src/Symfony/Component/Process/Exception/ProcessFailedException.php +++ b/src/Symfony/Component/Process/Exception/ProcessFailedException.php @@ -30,8 +30,10 @@ class ProcessFailedException extends RuntimeException 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() ) diff --git a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php index 9bc2fdf30f..4a1a1daaaf 100644 --- a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php @@ -46,12 +46,14 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase 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()) @@ -63,11 +65,17 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase $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() ); }