From 4530d3db922ecfd6e79ddb4166d11d70f12942db Mon Sep 17 00:00:00 2001 From: sebastianstucke87 <47354551+sebastianstucke87@users.noreply.github.com> Date: Wed, 8 May 2024 20:09:17 +0200 Subject: [PATCH] Add "andShould" (#326) (#427) * feat: add "andShould" (#326) --- src/Rules/Because.php | 8 +++++ src/Rules/DSL/BecauseParser.php | 4 +++ .../CheckClassWithMultipleExpressionsTest.php | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php diff --git a/src/Rules/Because.php b/src/Rules/Because.php index 198c772a..539ac97a 100644 --- a/src/Rules/Because.php +++ b/src/Rules/Because.php @@ -3,6 +3,7 @@ namespace Arkitect\Rules; +use Arkitect\Expression\Expression; use Arkitect\Rules\DSL\ArchRule; use Arkitect\Rules\DSL\BecauseParser; @@ -22,4 +23,11 @@ public function because(string $reason): ArchRule return $this->ruleBuilder->build(); } + + public function andShould(Expression $expression): BecauseParser + { + $this->ruleBuilder->addShould($expression); + + return $this; + } } diff --git a/src/Rules/DSL/BecauseParser.php b/src/Rules/DSL/BecauseParser.php index ca9aa280..87a54097 100644 --- a/src/Rules/DSL/BecauseParser.php +++ b/src/Rules/DSL/BecauseParser.php @@ -3,7 +3,11 @@ namespace Arkitect\Rules\DSL; +use Arkitect\Expression\Expression; + interface BecauseParser { public function because(string $reason): ArchRule; + + public function andShould(Expression $expression): self; } diff --git a/tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php b/tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php new file mode 100644 index 00000000..8c7c588c --- /dev/null +++ b/tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php @@ -0,0 +1,36 @@ +that(new ResideInOneOfTheseNamespaces('App\BadCode')) + ->andThat(new ResideInOneOfTheseNamespaces('App\HappyIsland')) + ->should(new IsNotFinal()) + ->andShould(new IsNotReadonly()) + ->andShould(new IsNotAbstract()) + ->andShould(new IsNotEnum()) + ->andShould(new IsNotInterface()) + ->andShould(new IsNotTrait()) + ->because('some reason'); + + ArchRuleTestCase::assertArchRule($rule, $set); + } +}