generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9d8373
commit c4fb047
Showing
8 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace OhDear\HealthCheckReport; | ||
|
||
class Line | ||
{ | ||
public static function make( | ||
string $name, | ||
string $message = '', | ||
string $status = '', | ||
array $meta = [], | ||
): self { | ||
return new static(...func_get_args()); | ||
} | ||
|
||
public function __construct( | ||
protected string $name, | ||
protected string $message = '', | ||
protected string $status = '', | ||
protected array $meta = [], | ||
) { | ||
} | ||
|
||
public function message(string $message): self | ||
{ | ||
$this->message = $message; | ||
|
||
return $this; | ||
} | ||
|
||
public function status(string $status): self | ||
{ | ||
$this->status = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function meta(array $meta): self | ||
{ | ||
$this->meta = $meta; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'message' => $this->message, | ||
'status' => $this->status, | ||
'meta' => $this->meta, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace OhDear\HealthCheckReport; | ||
|
||
use DateTime; | ||
use DateTimeInterface; | ||
|
||
class Report | ||
{ | ||
protected DateTimeInterface $finishedAt; | ||
|
||
/** @var array<int, Line> */ | ||
protected array $lines; | ||
|
||
/** | ||
* @param \DateTimeInterface|null $finishedAt | ||
* @param array<int, Line> $lines | ||
*/ | ||
public function __construct(DateTimeInterface $finishedAt = null, array $lines = []) | ||
{ | ||
$this->finishedAt = $finishedAt ?? new DateTime(); | ||
|
||
$this->lines = $lines; | ||
} | ||
|
||
public function addLine(Line $lines) | ||
{ | ||
$this->lines[] = $lines; | ||
} | ||
|
||
public function toJson(): string | ||
{ | ||
$lines = array_map(fn (Line $line) => $line->toArray(), $this->lines); | ||
|
||
return json_encode([ | ||
'finishedAt' => $this->finishedAt->format('Y-m-d H:i:s'), | ||
'lines' => $lines, | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use OhDear\HealthCheckReport\Line; | ||
use OhDear\HealthCheckReport\Report; | ||
use function Spatie\Snapshots\assertMatchesSnapshot; | ||
|
||
it('can create create report', function () { | ||
$lines = [ | ||
new Line( | ||
'name', | ||
'message', | ||
'ok', | ||
['name' => 'value'] | ||
) | ||
]; | ||
|
||
$report = new Report( | ||
finishedAt: new DateTimeImmutable('2001-01-01 00:00:00'), | ||
lines: $lines, | ||
); | ||
|
||
assertMatchesSnapshot($report->toJson()); | ||
}); |
1 change: 1 addition & 0 deletions
1
tests/__snapshots__/ReportTest__it_can_create_create_report__1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"finishedAt":"2001-01-01 00:00:00","lines":[{"name":"name","message":"message","status":"ok","meta":{"name":"value"}}]} |