|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Arkitect\Tests\Unit\Expressions\ForClasses; |
| 6 | + |
| 7 | +use Arkitect\Analyzer\ClassDescriptionBuilder; |
| 8 | +use Arkitect\Expression\ForClasses\IsMapped; |
| 9 | +use Arkitect\Rules\Violations; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +final class IsMappedTest extends TestCase |
| 13 | +{ |
| 14 | + public function test_it_should_not_add_violation_if_fqcn_is_in_list(): void |
| 15 | + { |
| 16 | + $listedFqcn = 'App\SharedKernel\Component\MyClass'; |
| 17 | + $list = [ |
| 18 | + 'a' => $listedFqcn, |
| 19 | + 'b' => 'App\SharedKernel\Component\MyOtherClass', |
| 20 | + ]; |
| 21 | + $expression = new IsMapped($list); |
| 22 | + $classDescription = (new ClassDescriptionBuilder())->setClassName($listedFqcn)->build(); |
| 23 | + |
| 24 | + $violations = new Violations(); |
| 25 | + $expression->evaluate($classDescription, $violations, ''); |
| 26 | + |
| 27 | + self::assertEquals(0, $violations->count()); |
| 28 | + } |
| 29 | + |
| 30 | + public function test_it_should_add_violation_if_fqcn_is_not_in_list(): void |
| 31 | + { |
| 32 | + $nonListedFqcn = 'App\SharedKernel\Component\MyClass'; |
| 33 | + $list = [ |
| 34 | + 'a' => 'App\SharedKernel\Component\SomeClass', |
| 35 | + 'b' => 'App\SharedKernel\Component\MyOtherClass', |
| 36 | + ]; |
| 37 | + $expression = new IsMapped($list); |
| 38 | + $classDescription = (new ClassDescriptionBuilder())->setClassName($nonListedFqcn)->build(); |
| 39 | + |
| 40 | + $violations = new Violations(); |
| 41 | + $expression->evaluate($classDescription, $violations, ''); |
| 42 | + |
| 43 | + self::assertEquals(1, $violations->count()); |
| 44 | + self::assertEquals(IsMapped::POSITIVE_DESCRIPTION, $expression->describe($classDescription, '')->toString()); |
| 45 | + } |
| 46 | +} |
0 commit comments