Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "andShould" (#326) #427

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading