From 8bb07895328a2b64e8862482d31ae8ea6ab260c6 Mon Sep 17 00:00:00 2001 From: Maarten Paauw Date: Fri, 20 Sep 2024 15:30:54 +0200 Subject: [PATCH] feat: add dissatisfies method to has specifications trait --- src/HasSpecifications.php | 8 ++++++++ tests/HasSpecificationsTest.php | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/HasSpecifications.php b/src/HasSpecifications.php index bea253e..3023f30 100644 --- a/src/HasSpecifications.php +++ b/src/HasSpecifications.php @@ -14,6 +14,14 @@ public function satisfies(Specification $specification): bool return $specification->isSatisfiedBy($this); } + /** + * @param Specification $specification + */ + public function dissatisfies(Specification $specification): bool + { + return (new NotSpecification($specification))->isSatisfiedBy($this); + } + /** * @deprecated use `satisfies()` instead * diff --git a/tests/HasSpecificationsTest.php b/tests/HasSpecificationsTest.php index a330fd7..5e1c0cf 100644 --- a/tests/HasSpecificationsTest.php +++ b/tests/HasSpecificationsTest.php @@ -23,5 +23,8 @@ public function test_it_should_pass_the_candidate_to_the_specification(): void // Act + Assert $this->assertTrue($candidate->satisfies(new PositiveSpecification())); $this->assertFalse($candidate->satisfies(new NegativeSpecification())); + + $this->assertFalse($candidate->dissatisfies(new PositiveSpecification())); + $this->assertTrue($candidate->dissatisfies(new NegativeSpecification())); } }