Skip to content

Commit

Permalink
Merge pull request #71 from dominikkukacka/main
Browse files Browse the repository at this point in the history
Fix allChecksOk and containsFailingCheck behaviour
  • Loading branch information
freekmurze authored Feb 9, 2022
2 parents a0ffad5 + 0629007 commit 7389497
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ResultStores/StoredCheckResults/StoredCheckResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public function addCheck(StoredCheckResult $line): self

public function allChecksOk(): bool
{
return $this->storedCheckResults->contains(
fn (StoredCheckResult $line) => $line->status !== Status::ok()->value
);
return ! $this->containsFailingCheck();
}

public function containsFailingCheck(): bool
{
return ! $this->allChecksOk();
return $this->storedCheckResults->contains(
fn (StoredCheckResult $line) => $line->status !== Status::ok()->value
);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/ResultStores/StoredCheckResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
expect($storedCheckResults->containsCheckWithStatus([Status::crashed(), Status::failed()]))->toBeFalse();
});

it('has a method to check if one or more checks are failing', function () {
$storedCheckResults = new StoredCheckResults(new DateTime(), collect([
makeStoredCheckResultWithStatus(Status::warning()),
makeStoredCheckResultWithStatus(Status::ok()),
]));
expect($storedCheckResults->containsFailingCheck())->toBeTrue();
});

it('has a method to check if all checks are good', function () {
$storedCheckResults = new StoredCheckResults(new DateTime(), collect([
makeStoredCheckResultWithStatus(Status::ok()),
makeStoredCheckResultWithStatus(Status::ok()),
]));
expect($storedCheckResults->allChecksOk())->toBeTrue();
});

function makeStoredCheckResultWithStatus(Status $status): StoredCheckResult
{
return StoredCheckResult::make(
Expand Down

0 comments on commit 7389497

Please sign in to comment.