Add unit tests for basic classes by tdgroot · Pull Request #191 · ByteInternet/hypernode-deploy · GitHub
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
3 changes: 3 additions & 0 deletions .gitignore
13 changes: 10 additions & 3 deletions src/Report/ReportLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

class ReportLoader
{
private string $reportPath;

public function __construct(string $reportPath = Report::REPORT_FILENAME)
{
$this->reportPath = $reportPath;
}

public function loadReport(): ?Report
{
if (file_exists(Report::REPORT_FILENAME)) {
$contents = file_get_contents(Report::REPORT_FILENAME);
$data = json_decode($contents, true, JSON_THROW_ON_ERROR);
if (file_exists($this->reportPath)) {
$contents = file_get_contents($this->reportPath);
$data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
Assert::isArray($data);
return Report::fromArray($data);
}
Expand Down
9 changes: 8 additions & 1 deletion src/Report/ReportWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

class ReportWriter
{
private string $reportPath;

public function __construct(string $reportPath = Report::REPORT_FILENAME)
{
$this->reportPath = $reportPath;
}

public function write(Report $report): void
{
file_put_contents(Report::REPORT_FILENAME, json_encode($report->toArray()));
file_put_contents($this->reportPath, json_encode($report->toArray()));
}
}
305 changes: 305 additions & 0 deletions tests/Unit/Console/Output/ConsoleLoggerTest.php
Loading
Loading