Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/TaskLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
public function __construct(array $data)
{
foreach ($data as $key => $value) {
if (property_exists($this, $key)) {
if ($key === 'output') {
$this->output = $this->setOutput($value);
} elseif (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
Expand All @@ -68,4 +70,22 @@
return $this->{$key};
}
}

/**
* Unify output to string.
*
* @param array<int, string>|bool|int|string|null $value
*/
private function setOutput($value): ?string
{
if (is_string($value) || $value === null) {
return $value;
}

if (is_array($value)) {
return implode(PHP_EOL, $value);

Check warning on line 86 in src/TaskLog.php

View workflow job for this annotation

GitHub Actions / infection / Mutation Testing

Escaped Mutant for Mutator "FunctionCall": @@ @@ return $value; } if (is_array($value)) { - return implode(PHP_EOL, $value); + implode(PHP_EOL, $value); + return null; } return (string) $value; } }
}

return (string) $value;
}
}
13 changes: 8 additions & 5 deletions tests/unit/TaskLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,38 @@ public static function provideDuration(): iterable
'2021-01-21 12:00:00',
'2021-01-21 12:00:00',
'0.00',
['first item', 'second item'],
],
[
'2021-01-21 12:00:00',
'2021-01-21 12:00:01',
'1.00',
true,
],
[
'2021-01-21 12:00:00',
'2021-01-21 12:05:12',
'312.00',
null,
],
];
}

/**
* @dataProvider provideDuration
*
* @param mixed $start
* @param mixed $end
* @param mixed $expected
* @param array|bool|int|string|null $output
*
* @throws Exception
*/
public function testDuration($start, $end, $expected)
public function testDuration(string $start, string $end, string $expected, $output)
{
$start = new Time($start);
$end = new Time($end);

$log = new TaskLog([
'task' => new Task('closure', static function () {}),
'output' => '',
'output' => $output,
'runStart' => $start,
'runEnd' => $end,
'error' => null,
Expand Down
Loading