|
3 | 3 |
|
4 | 4 | namespace Arkitect\Tests\Unit\Architecture;
|
5 | 5 |
|
| 6 | +use Arkitect\Expression\ForClasses\Andx; |
6 | 7 | use Arkitect\Expression\ForClasses\DependsOnlyOnTheseNamespaces;
|
| 8 | +use Arkitect\Expression\ForClasses\Not; |
7 | 9 | use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
|
8 | 10 | use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
|
9 | 11 | use Arkitect\RuleBuilders\Architecture\Architecture;
|
@@ -39,6 +41,71 @@ public function test_layered_architecture(): void
|
39 | 41 | self::assertEquals($expectedRules, iterator_to_array($rules));
|
40 | 42 | }
|
41 | 43 |
|
| 44 | + public function test_layered_architecture_with_expression(): void |
| 45 | + { |
| 46 | + $rules = Architecture::withComponents() |
| 47 | + ->component('Domain')->definedByExpression(new ResideInOneOfTheseNamespaces('App\*\Domain\*')) |
| 48 | + ->component('Application')->definedByExpression(new ResideInOneOfTheseNamespaces('App\*\Application\*')) |
| 49 | + ->component('Infrastructure') |
| 50 | + ->definedByExpression(new ResideInOneOfTheseNamespaces('App\*\Infrastructure\*')) |
| 51 | + |
| 52 | + ->where('Domain')->shouldNotDependOnAnyComponent() |
| 53 | + ->where('Application')->mayDependOnComponents('Domain') |
| 54 | + ->where('Infrastructure')->mayDependOnAnyComponent() |
| 55 | + |
| 56 | + ->rules(); |
| 57 | + |
| 58 | + $expectedRules = [ |
| 59 | + Rule::allClasses() |
| 60 | + ->that(new ResideInOneOfTheseNamespaces('App\*\Domain\*')) |
| 61 | + ->should(new Not(new Andx( |
| 62 | + new ResideInOneOfTheseNamespaces('App\*\Application\*'), |
| 63 | + new ResideInOneOfTheseNamespaces('App\*\Infrastructure\*') |
| 64 | + ))) |
| 65 | + ->because('of component architecture'), |
| 66 | + Rule::allClasses() |
| 67 | + ->that(new ResideInOneOfTheseNamespaces('App\*\Application\*')) |
| 68 | + ->should(new Not(new Andx( |
| 69 | + new ResideInOneOfTheseNamespaces('App\*\Infrastructure\*') |
| 70 | + ))) |
| 71 | + ->because('of component architecture'), |
| 72 | + ]; |
| 73 | + |
| 74 | + self::assertEquals($expectedRules, iterator_to_array($rules)); |
| 75 | + } |
| 76 | + |
| 77 | + public function test_layered_architecture_with_mix_of_namespace_and_expression(): void |
| 78 | + { |
| 79 | + $rules = Architecture::withComponents() |
| 80 | + ->component('Domain')->definedByExpression(new ResideInOneOfTheseNamespaces('App\*\Domain\*')) |
| 81 | + ->component('Application')->definedByExpression(new ResideInOneOfTheseNamespaces('App\*\Application\*')) |
| 82 | + ->component('Infrastructure')->definedBy('App\*\Infrastructure\*') |
| 83 | + |
| 84 | + ->where('Domain')->shouldNotDependOnAnyComponent() |
| 85 | + ->where('Application')->mayDependOnComponents('Domain') |
| 86 | + ->where('Infrastructure')->mayDependOnAnyComponent() |
| 87 | + |
| 88 | + ->rules(); |
| 89 | + |
| 90 | + $expectedRules = [ |
| 91 | + Rule::allClasses() |
| 92 | + ->that(new ResideInOneOfTheseNamespaces('App\*\Domain\*')) |
| 93 | + ->should(new Andx( |
| 94 | + new NotDependsOnTheseNamespaces('App\*\Infrastructure\*'), |
| 95 | + new Not(new Andx( |
| 96 | + new ResideInOneOfTheseNamespaces('App\*\Application\*'), |
| 97 | + )) |
| 98 | + )) |
| 99 | + ->because('of component architecture'), |
| 100 | + Rule::allClasses() |
| 101 | + ->that(new ResideInOneOfTheseNamespaces('App\*\Application\*')) |
| 102 | + ->should(new NotDependsOnTheseNamespaces('App\*\Infrastructure\*')) |
| 103 | + ->because('of component architecture'), |
| 104 | + ]; |
| 105 | + |
| 106 | + self::assertEquals($expectedRules, iterator_to_array($rules)); |
| 107 | + } |
| 108 | + |
42 | 109 | public function test_layered_architecture_with_depends_only_on_components(): void
|
43 | 110 | {
|
44 | 111 | $rules = Architecture::withComponents()
|
|
0 commit comments