Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f283e9b

Browse files
committed
fix: unify the logged output of the task result
1 parent ec717c4 commit f283e9b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

‎src/TaskLog.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class TaskLog
4141
public function __construct(array $data)
4242
{
4343
foreach ($data as $key => $value) {
44-
if (property_exists($this, $key)) {
44+
if ($key === 'output') {
45+
$this->output = $this->setOutput($value);
46+
} elseif (property_exists($this, $key)) {
4547
$this->{$key} = $value;
4648
}
4749
}
@@ -68,4 +70,22 @@ public function __get(string $key)
6870
return $this->{$key};
6971
}
7072
}
73+
74+
/**
75+
* Unify output to string.
76+
*
77+
* @param array|bool|int|string|null $value
78+
*/
79+
protected function setOutput($value): ?string
80+
{
81+
if (is_string($value) || $value === null) {
82+
return $value;
83+
}
84+
85+
if (is_array($value)) {
86+
return implode(PHP_EOL, $value);
87+
}
88+
89+
return (string) $value;
90+
}
7191
}

‎tests/unit/TaskLogTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,38 @@ public static function provideDuration(): iterable
2828
'2021年01月21日 12:00:00',
2929
'2021年01月21日 12:00:00',
3030
'0.00',
31+
['first item', 'second item'],
3132
],
3233
[
3334
'2021年01月21日 12:00:00',
3435
'2021年01月21日 12:00:01',
3536
'1.00',
37+
true,
3638
],
3739
[
3840
'2021年01月21日 12:00:00',
3941
'2021年01月21日 12:05:12',
4042
'312.00',
43+
null,
4144
],
4245
];
4346
}
4447

4548
/**
4649
* @dataProvider provideDuration
4750
*
48-
* @param mixed $start
49-
* @param mixed $end
50-
* @param mixed $expected
51+
* @param array|bool|int|string|null $output
52+
*
53+
* @throws Exception
5154
*/
52-
public function testDuration($start, $end, $expected)
55+
public function testDuration(string$start, string$end, string$expected, $output)
5356
{
5457
$start = new Time($start);
5558
$end = new Time($end);
5659

5760
$log = new TaskLog([
5861
'task' => new Task('closure', static function () {}),
59-
'output' => '',
62+
'output' => $output,
6063
'runStart' => $start,
6164
'runEnd' => $end,
6265
'error' => null,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /