File tree Expand file tree Collapse file tree 7 files changed +41
-4
lines changed Expand file tree Collapse file tree 7 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 20
20
"illuminate/console" : " ^10.0|^11.0" ,
21
21
"illuminate/support" : " ^10.0|^11.0" ,
22
22
"spatie/laravel-package-tools" : " ^1.16.2" ,
23
- "symfony/polyfill-php83" : " ^1.30"
23
+ "symfony/polyfill-php83" : " ^1.30" ,
24
+ "webmozart/assert" : " ^1.11"
24
25
},
25
26
"require-dev" : {
26
27
"illuminate/testing" : " ^10.0|^11.0" ,
Original file line number Diff line number Diff line change 5
5
namespace Maartenpaauw \Specifications ;
6
6
7
7
use Override ;
8
+ use Webmozart \Assert \Assert ;
8
9
9
10
/**
10
11
* @template TCandidate
@@ -18,7 +19,9 @@ final class AndSpecification extends CompositeSpecification
18
19
*/
19
20
public function __construct (
20
21
private readonly array $ specifications ,
21
- ) {}
22
+ ) {
23
+ Assert::allIsInstanceOf ($ specifications , Specification::class);
24
+ }
22
25
23
26
#[Override]
24
27
public function isSatisfiedBy (mixed $ candidate ): bool
Original file line number Diff line number Diff line change 5
5
namespace Maartenpaauw \Specifications ;
6
6
7
7
use Override ;
8
+ use Webmozart \Assert \Assert ;
8
9
9
10
/**
10
11
* @template TCandidate
@@ -18,7 +19,9 @@ final class OrSpecification extends CompositeSpecification
18
19
*/
19
20
public function __construct (
20
21
private readonly array $ specifications ,
21
- ) {}
22
+ ) {
23
+ Assert::allIsInstanceOf ($ this ->specifications , Specification::class);
24
+ }
22
25
23
26
#[Override]
24
27
public function isSatisfiedBy (mixed $ candidate ): bool
Original file line number Diff line number Diff line change 5
5
namespace Maartenpaauw \Specifications ;
6
6
7
7
use Override ;
8
+ use Webmozart \Assert \Assert ;
8
9
9
10
/**
10
11
* @template TCandidate
@@ -18,7 +19,9 @@ final class XorSpecification extends CompositeSpecification
18
19
*/
19
20
public function __construct (
20
21
private readonly array $ specifications ,
21
- ) {}
22
+ ) {
23
+ Assert::allIsInstanceOf ($ specifications , Specification::class);
24
+ }
22
25
23
26
#[Override]
24
27
public function isSatisfiedBy (mixed $ candidate ): bool
Original file line number Diff line number Diff line change 4
4
5
5
namespace Maartenpaauw \Specifications \Tests ;
6
6
7
+ use InvalidArgumentException ;
7
8
use Maartenpaauw \Specifications \AndSpecification ;
8
9
use Workbench \App \LengthSpecification ;
9
10
use Workbench \App \UppercaseSpecification ;
@@ -30,6 +31,14 @@ protected function setUp(): void
30
31
]);
31
32
}
32
33
34
+ public function test_it_should_throw_an_invalid_argument_exception_when_the_specification_array_does_contain_invalid_data (): void
35
+ {
36
+ self ::expectException (InvalidArgumentException::class);
37
+
38
+ // @phpstan-ignore-next-line
39
+ new AndSpecification (['invalid ' ]);
40
+ }
41
+
33
42
public function test_it_should_return_true_when_the_candidate_matches_all_specifications (): void
34
43
{
35
44
// Act
Original file line number Diff line number Diff line change 4
4
5
5
namespace Maartenpaauw \Specifications \Tests ;
6
6
7
+ use InvalidArgumentException ;
7
8
use Maartenpaauw \Specifications \OrSpecification ;
8
9
use Workbench \App \LengthSpecification ;
9
10
use Workbench \App \UppercaseSpecification ;
@@ -30,6 +31,14 @@ protected function setUp(): void
30
31
]);
31
32
}
32
33
34
+ public function test_it_should_throw_an_invalid_argument_exception_when_the_specification_array_does_contain_invalid_data (): void
35
+ {
36
+ self ::expectException (InvalidArgumentException::class);
37
+
38
+ // @phpstan-ignore-next-line
39
+ new OrSpecification (['invalid ' ]);
40
+ }
41
+
33
42
public function test_it_should_return_true_when_the_candidate_matches_all_specifications (): void
34
43
{
35
44
// Act
Original file line number Diff line number Diff line change 4
4
5
5
namespace Maartenpaauw \Specifications \Tests ;
6
6
7
+ use InvalidArgumentException ;
7
8
use Maartenpaauw \Specifications \XorSpecification ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
use Workbench \App \LengthSpecification ;
@@ -31,6 +32,14 @@ protected function setUp(): void
31
32
]);
32
33
}
33
34
35
+ public function test_it_should_throw_an_invalid_argument_exception_when_the_specification_array_does_contain_invalid_data (): void
36
+ {
37
+ self ::expectException (InvalidArgumentException::class);
38
+
39
+ // @phpstan-ignore-next-line
40
+ new XorSpecification (['invalid ' ]);
41
+ }
42
+
34
43
public function test_it_should_only_return_true_when_one_specification_is_satisfied (): void
35
44
{
36
45
$ this ->assertTrue ($ this ->specification ->isSatisfiedBy ('HELLO ' ));
You can’t perform that action at this time.
0 commit comments