Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 849703a

Browse filesBrowse files
Taluufabpot
authored andcommitted
When a process fails, check if the output is enabled
With the recent addition of the ability to disable the output, it was not taken into account within the `ProcessFailedException`. So, if the output was indeed disabled, and the process returns an error (i.e via a `mustRun`) we could have another LogicException which is not expected.
1 parent d6fccdd commit 849703a
Copy full SHA for 849703a

File tree

Expand file treeCollapse file tree

2 files changed

+66
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+66
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Exception/ProcessFailedException.php
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ public function __construct(Process $process)
2828
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
2929
}
3030

31-
parent::__construct(
32-
sprintf(
33-
'The command "%s" failed.'."\nExit Code: %s(%s)\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
34-
$process->getCommandLine(),
35-
$process->getExitCode(),
36-
$process->getExitCodeText(),
31+
$error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
32+
$process->getCommandLine(),
33+
$process->getExitCode(),
34+
$process->getExitCodeText()
35+
);
36+
37+
if (!$process->isOutputDisabled()) {
38+
$error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
3739
$process->getOutput(),
3840
$process->getErrorOutput()
39-
)
40-
);
41+
);
42+
}
43+
44+
parent::__construct($error);
4145

4246
$this->process = $process;
4347
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php
+54-1Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,83 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
5454

5555
$process = $this->getMock(
5656
'Symfony\Component\Process\Process',
57-
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText'),
57+
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled'),
5858
array($cmd)
5959
);
6060
$process->expects($this->once())
6161
->method('isSuccessful')
6262
->will($this->returnValue(false));
63+
6364
$process->expects($this->once())
6465
->method('getOutput')
6566
->will($this->returnValue($output));
67+
6668
$process->expects($this->once())
6769
->method('getErrorOutput')
6870
->will($this->returnValue($errorOutput));
71+
6972
$process->expects($this->once())
7073
->method('getExitCode')
7174
->will($this->returnValue($exitCode));
75+
7276
$process->expects($this->once())
7377
->method('getExitCodeText')
7478
->will($this->returnValue($exitText));
7579

80+
$process->expects($this->once())
81+
->method('isOutputDisabled')
82+
->will($this->returnValue(false));
83+
7684
$exception = new ProcessFailedException($process);
7785

7886
$this->assertEquals(
7987
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
8088
$exception->getMessage()
8189
);
8290
}
91+
92+
/**
93+
* Tests that ProcessFailedException does not extract information from
94+
* process output if it was previously disabled
95+
*/
96+
public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
97+
{
98+
$cmd = 'php';
99+
$exitCode = 1;
100+
$exitText = 'General error';
101+
102+
$process = $this->getMock(
103+
'Symfony\Component\Process\Process',
104+
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput'),
105+
array($cmd)
106+
);
107+
$process->expects($this->once())
108+
->method('isSuccessful')
109+
->will($this->returnValue(false));
110+
111+
$process->expects($this->never())
112+
->method('getOutput');
113+
114+
$process->expects($this->never())
115+
->method('getErrorOutput');
116+
117+
$process->expects($this->once())
118+
->method('getExitCode')
119+
->will($this->returnValue($exitCode));
120+
121+
$process->expects($this->once())
122+
->method('getExitCodeText')
123+
->will($this->returnValue($exitText));
124+
125+
$process->expects($this->once())
126+
->method('isOutputDisabled')
127+
->will($this->returnValue(true));
128+
129+
$exception = new ProcessFailedException($process);
130+
131+
$this->assertEquals(
132+
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)",
133+
$exception->getMessage()
134+
);
135+
}
83136
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.