Skip to content

Commit

Permalink
Merge pull request #3 from akuzia/error-output
Browse files Browse the repository at this point in the history
getErrorOutput wont fallback to stdout
  • Loading branch information
muxx authored May 13, 2021
2 parents 479bc06 + 6c62b1a commit b862a95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Dplr/TaskReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
31 changes: 31 additions & 0 deletions tests/Dplr/Tests/TaskReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit b862a95

Please sign in to comment.