File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ All notable changes to `laravel-specification-pattern` will be documented in thi
8
8
9
9
- Ability to make specification verbose using composite specification.
10
10
- Exclusive or specification.
11
+ - ` HasSpecifications ` trait.
11
12
12
13
## [ v2.2.0] - 2024-03-13
13
14
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Maartenpaauw \Specifications ;
6
+
7
+ trait HasSpecifications
8
+ {
9
+ /**
10
+ * @param Specification<self> $specification
11
+ */
12
+ public function meets (Specification $ specification ): bool
13
+ {
14
+ return $ specification ->isSatisfiedBy ($ this );
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Maartenpaauw \Specifications \Tests ;
6
+
7
+ use Workbench \App \Candidate ;
8
+ use Workbench \App \NegativeSpecification ;
9
+ use Workbench \App \PositiveSpecification ;
10
+
11
+ /**
12
+ * @internal
13
+ *
14
+ * @small
15
+ */
16
+ final class HasSpecificationsTest extends TestCase
17
+ {
18
+ public function test_it_should_pass_the_candidate_to_the_specification (): void
19
+ {
20
+ // Arrange
21
+ $ candidate = new Candidate ();
22
+
23
+ // Act + Assert
24
+ $ this ->assertTrue ($ candidate ->meets (new PositiveSpecification ()));
25
+ $ this ->assertFalse ($ candidate ->meets (new NegativeSpecification ()));
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Workbench \App ;
6
+
7
+ use Maartenpaauw \Specifications \HasSpecifications ;
8
+
9
+ final class Candidate
10
+ {
11
+ use HasSpecifications;
12
+ }
You can’t perform that action at this time.
0 commit comments