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
This commit is contained in:
Richard van Laak 2015-06-08 12:48:52 +02:00 committed by Richard
parent a44ceb3156
commit dbaefb4f5f
2 changed files with 18 additions and 7 deletions

View File

@ -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()) {

View File

@ -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()
);
}