Skip to content

Commit

Permalink
Add "andShould" (#326) (#427)
Browse files Browse the repository at this point in the history
* feat: add "andShould" (#326)
  • Loading branch information
sebastianstucke87 authored May 8, 2024
1 parent 1240ec9 commit 4530d3d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Rules/Because.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Arkitect\Rules;

use Arkitect\Expression\Expression;
use Arkitect\Rules\DSL\ArchRule;
use Arkitect\Rules\DSL\BecauseParser;

Expand All @@ -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;
}
}
4 changes: 4 additions & 0 deletions src/Rules/DSL/BecauseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
36 changes: 36 additions & 0 deletions tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);

namespace Arkitect\Tests\E2E\PHPUnit;

use Arkitect\ClassSet;
use Arkitect\Expression\ForClasses\IsNotAbstract;
use Arkitect\Expression\ForClasses\IsNotEnum;
use Arkitect\Expression\ForClasses\IsNotFinal;
use Arkitect\Expression\ForClasses\IsNotInterface;
use Arkitect\Expression\ForClasses\IsNotReadonly;
use Arkitect\Expression\ForClasses\IsNotTrait;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
use PHPUnit\Framework\TestCase;

class CheckClassWithMultipleExpressionsTest extends TestCase
{
public function test_it_can_check_multiple_expressions(): void
{
$set = ClassSet::fromDir(__DIR__.'/../_fixtures/happy_island');

$rule = Rule::allClasses()
->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);
}
}

0 comments on commit 4530d3d

Please sign in to comment.