Skip to content

Commit 09fd2af

Browse files
committed
merged branch zakharovvi/process_exception_exitcode (PR #7628)
This PR was merged into the master branch. Discussion ---------- [Process] added exit code to ProcessFailedException message | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | n/a Commits ------- 7519fdc [Process] added exit code to ProcessFailedException message
2 parents 3cb87a3 + 7519fdc commit 09fd2af

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public function __construct(Process $process)
3030

3131
parent::__construct(
3232
sprintf(
33-
'The command "%s" failed.'."\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
33+
'The command "%s" failed.'."\nExit Code: %s(%s)\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
3434
$process->getCommandLine(),
35+
$process->getExitCode(),
36+
$process->getExitCodeText(),
3537
$process->getOutput(),
3638
$process->getErrorOutput()
3739
)

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ public function testProcessFailedExceptionThrowsException()
4646
public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
4747
{
4848
$cmd = 'php';
49+
$exitCode = 1;
50+
$exitText = 'General error';
4951
$output = "Command output";
5052
$errorOutput = "FATAL: Unexpected error";
5153

5254
$process = $this->getMock(
5355
'Symfony\Component\Process\Process',
54-
array('isSuccessful', 'getOutput', 'getErrorOutput'),
56+
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText'),
5557
array($cmd)
5658
);
5759
$process->expects($this->once())
@@ -63,11 +65,17 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
6365
$process->expects($this->once())
6466
->method('getErrorOutput')
6567
->will($this->returnValue($errorOutput));
68+
$process->expects($this->once())
69+
->method('getExitCode')
70+
->will($this->returnValue($exitCode));
71+
$process->expects($this->once())
72+
->method('getExitCodeText')
73+
->will($this->returnValue($exitText));
6674

6775
$exception = new ProcessFailedException($process);
6876

6977
$this->assertEquals(
70-
"The command \"$cmd\" failed.\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
78+
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
7179
$exception->getMessage()
7280
);
7381
}

0 commit comments

Comments
 (0)