Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d83cea

Browse files
committed
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
1 parent a44ceb3 commit 4d83cea

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Symfony/Component/Process/Exception/ProcessFailedException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public function __construct(Process $process)
2828
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
2929
}
3030

31-
$error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
31+
$error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
3232
$process->getCommandLine(),
3333
$process->getExitCode(),
34-
$process->getExitCodeText()
34+
$process->getExitCodeText(),
35+
$process->getWorkingDirectory()
3536
);
3637

3738
if (!$process->isOutputDisabled()) {

src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
5151
$exitText = 'General error';
5252
$output = 'Command output';
5353
$errorOutput = 'FATAL: Unexpected error';
54+
$workingDirectory = getcwd();
5455

5556
$process = $this->getMock(
5657
'Symfony\Component\Process\Process',
57-
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled'),
58+
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
5859
array($cmd)
5960
);
6061
$process->expects($this->once())
@@ -81,10 +82,14 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
8182
->method('isOutputDisabled')
8283
->will($this->returnValue(false));
8384

85+
$process->expects($this->once())
86+
->method('getWorkingDirectory')
87+
->will($this->returnValue($workingDirectory));
88+
8489
$exception = new ProcessFailedException($process);
8590

8691
$this->assertEquals(
87-
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
92+
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
8893
$exception->getMessage()
8994
);
9095
}
@@ -98,10 +103,11 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
98103
$cmd = 'php';
99104
$exitCode = 1;
100105
$exitText = 'General error';
101-
106+
$workingDirectory = getcwd();
107+
102108
$process = $this->getMock(
103109
'Symfony\Component\Process\Process',
104-
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput'),
110+
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
105111
array($cmd)
106112
);
107113
$process->expects($this->once())
@@ -125,11 +131,15 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
125131
$process->expects($this->once())
126132
->method('isOutputDisabled')
127133
->will($this->returnValue(true));
134+
135+
$process->expects($this->once())
136+
->method('getWorkingDirectory')
137+
->will($this->returnValue($workingDirectory));
128138

129139
$exception = new ProcessFailedException($process);
130140

131141
$this->assertEquals(
132-
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)",
142+
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
133143
$exception->getMessage()
134144
);
135145
}

0 commit comments

Comments
 (0)