diff --git a/CHANGELOG.md b/CHANGELOG.md index e55448f..6b7b81c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to `laravel-specification-pattern` will be documented in thi - Ability to make specification verbose using composite specification. - Exclusive or specification. +- `HasSpecifications` trait. ## [v2.2.0] - 2024-03-13 diff --git a/src/HasSpecifications.php b/src/HasSpecifications.php new file mode 100644 index 0000000..82dfee3 --- /dev/null +++ b/src/HasSpecifications.php @@ -0,0 +1,16 @@ + $specification + */ + public function meets(Specification $specification): bool + { + return $specification->isSatisfiedBy($this); + } +} diff --git a/tests/HasSpecificationsTest.php b/tests/HasSpecificationsTest.php new file mode 100644 index 0000000..5b266fb --- /dev/null +++ b/tests/HasSpecificationsTest.php @@ -0,0 +1,27 @@ +assertTrue($candidate->meets(new PositiveSpecification())); + $this->assertFalse($candidate->meets(new NegativeSpecification())); + } +} diff --git a/workbench/app/Candidate.php b/workbench/app/Candidate.php new file mode 100644 index 0000000..2fb1209 --- /dev/null +++ b/workbench/app/Candidate.php @@ -0,0 +1,12 @@ +