diff --git a/src/ResultStores/StoredCheckResults/StoredCheckResults.php b/src/ResultStores/StoredCheckResults/StoredCheckResults.php index 1249d462..c3f41f4f 100644 --- a/src/ResultStores/StoredCheckResults/StoredCheckResults.php +++ b/src/ResultStores/StoredCheckResults/StoredCheckResults.php @@ -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 + ); } /** diff --git a/tests/ResultStores/StoredCheckResultsTest.php b/tests/ResultStores/StoredCheckResultsTest.php index 19211b2b..5e2256a2 100644 --- a/tests/ResultStores/StoredCheckResultsTest.php +++ b/tests/ResultStores/StoredCheckResultsTest.php @@ -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(