From dbaefb4f5f9e26054b65f5dc336a5fd3763b179e Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Mon, 8 Jun 2015 12:48:52 +0200 Subject: [PATCH] Include working directory in ProcessFailedException ... because quite often the Exception is a result of the `www-data` user not having the appropriate rights at that path. fixed ProcessFailedException tests Update ProcessFailedExceptionTest.php fix indention fixed indention --- .../Exception/ProcessFailedException.php | 5 +++-- .../Tests/ProcessFailedExceptionTest.php | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Process/Exception/ProcessFailedException.php b/src/Symfony/Component/Process/Exception/ProcessFailedException.php index 7523a5e9cd..328acfde5e 100644 --- a/src/Symfony/Component/Process/Exception/ProcessFailedException.php +++ b/src/Symfony/Component/Process/Exception/ProcessFailedException.php @@ -28,10 +28,11 @@ class ProcessFailedException extends RuntimeException throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); } - $error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)", + $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s", $process->getCommandLine(), $process->getExitCode(), - $process->getExitCodeText() + $process->getExitCodeText(), + $process->getWorkingDirectory() ); if (!$process->isOutputDisabled()) { diff --git a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php index b028395f9b..0d763a470d 100644 --- a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php @@ -51,10 +51,11 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase $exitText = 'General error'; $output = 'Command output'; $errorOutput = 'FATAL: Unexpected error'; + $workingDirectory = getcwd(); $process = $this->getMock( 'Symfony\Component\Process\Process', - array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled'), + array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'), array($cmd) ); $process->expects($this->once()) @@ -81,27 +82,32 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase ->method('isOutputDisabled') ->will($this->returnValue(false)); + $process->expects($this->once()) + ->method('getWorkingDirectory') + ->will($this->returnValue($workingDirectory)); + $exception = new ProcessFailedException($process); $this->assertEquals( - "The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}", + "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}", $exception->getMessage() ); } /** * Tests that ProcessFailedException does not extract information from - * process output if it was previously disabled + * process output if it was previously disabled. */ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput() { $cmd = 'php'; $exitCode = 1; $exitText = 'General error'; + $workingDirectory = getcwd(); $process = $this->getMock( 'Symfony\Component\Process\Process', - array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput'), + array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'), array($cmd) ); $process->expects($this->once()) @@ -126,10 +132,14 @@ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase ->method('isOutputDisabled') ->will($this->returnValue(true)); + $process->expects($this->once()) + ->method('getWorkingDirectory') + ->will($this->returnValue($workingDirectory)); + $exception = new ProcessFailedException($process); $this->assertEquals( - "The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)", + "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}", $exception->getMessage() ); }