8000 bug #10530 [Process] Do not show output in FailedException if it was … · symfony/symfony@37d484c · GitHub
[go: up one dir, main page]

Skip to content

Commit 37d484c

Browse files
committed
bug #10530 [Process] Do not show output in FailedException if it was disabled (Taluu)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Process] Do not show output in FailedException if it was disabled | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ 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 and triggers a `ProcessFailedException` exception (i.e via a mustRun), we could have another LogicException which is not expected. Commits ------- 849703a When a process fails, check if the output is enabled
2 parents d6fccdd + 849703a commit 37d484c

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

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

Lines 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

Lines 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