diff --git a/src/Dplr/TaskReport.php b/src/Dplr/TaskReport.php index 9583d04..b823222 100644 --- a/src/Dplr/TaskReport.php +++ b/src/Dplr/TaskReport.php @@ -92,7 +92,7 @@ public function getOutput(): ?string public function getErrorOutput(): ?string { if (isset($this->data['Stderr'])) { - return $this->data['Stderr'] ?: $this->data['Stdout']; + return $this->data['Stderr']; } if (isset($this->data['ErrorMsg'])) { diff --git a/tests/Dplr/Tests/TaskReportTest.php b/tests/Dplr/Tests/TaskReportTest.php index e31adb1..57fe74b 100644 --- a/tests/Dplr/Tests/TaskReportTest.php +++ b/tests/Dplr/Tests/TaskReportTest.php @@ -66,4 +66,35 @@ public function testSuccessful() $this->assertNull($taskReport->getErrorOutput()); $this->assertEquals('output', $taskReport->getOutput()); } + + public function testNotSuccessfulWithoutStdout() + { + $taskReport = new TaskReport( + [ + 'Type' => TaskReport::TYPE_REPLY, + 'Success' => false, + 'Stderr' => 'error', + ], + new Task(['Action' => 'ssh', 'Cmd' => 'ls -al']) + ); + + $this->assertFalse($taskReport->isSuccessful()); + $this->assertEquals('error', $taskReport->getErrorOutput()); + $this->assertNull($taskReport->getOutput()); + } + + public function testNotSuccessfulWithoutStderr() + { + $taskReport = new TaskReport( + [ + 'Type' => TaskReport::TYPE_REPLY, + 'Success' => false, + ], + new Task(['Action' => 'ssh', 'Cmd' => 'ls -al']) + ); + + $this->assertFalse($taskReport->isSuccessful()); + $this->assertNull($taskReport->getErrorOutput()); + $this->assertNull($taskReport->getOutput()); + } }