From 3fc7f0baffc8a6725163d45c98e21aca0dbaac34 Mon Sep 17 00:00:00 2001 From: Dominik Kukacka Date: Tue, 8 Feb 2022 18:24:35 +0100 Subject: [PATCH 1/2] Fix allChecksOk and containsFailingCheck behaviour (the result was swapped) - Add tests for the functions --- .../StoredCheckResults/StoredCheckResults.php | 8 ++++---- tests/ResultStores/StoredCheckResultsTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) 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..ddde4044 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 cheks 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( From 062900756b60a5db8e929e73b3a3430b97b2576a Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Wed, 9 Feb 2022 09:01:00 +0100 Subject: [PATCH 2/2] Update StoredCheckResultsTest.php --- tests/ResultStores/StoredCheckResultsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ResultStores/StoredCheckResultsTest.php b/tests/ResultStores/StoredCheckResultsTest.php index ddde4044..5e2256a2 100644 --- a/tests/ResultStores/StoredCheckResultsTest.php +++ b/tests/ResultStores/StoredCheckResultsTest.php @@ -28,7 +28,7 @@ expect($storedCheckResults->containsFailingCheck())->toBeTrue(); }); -it('has a method to check if all cheks are good', function () { +it('has a method to check if all checks are good', function () { $storedCheckResults = new StoredCheckResults(new DateTime(), collect([ makeStoredCheckResultWithStatus(Status::ok()), makeStoredCheckResultWithStatus(Status::ok()),