|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace CodelyTv\Tests\Shared; |
| 6 | + |
| 7 | +use CodelyTv\Backoffice\Auth\Application\Authenticate\AuthenticateUserCommand; |
| 8 | +use CodelyTv\Shared\Domain\Bus\Event\DomainEventSubscriber; |
| 9 | +use CodelyTv\Shared\Domain\Bus\Query\Response; |
| 10 | +use CodelyTv\Tests\Shared\Infrastructure\ArchitectureTest; |
| 11 | +use CodelyTv\Tests\Shared\Infrastructure\Doctrine\MySqlDatabaseCleaner; |
| 12 | +use PHPat\Selector\Selector; |
| 13 | +use PHPat\Test\Builder\Rule; |
| 14 | +use PHPat\Test\PHPat; |
| 15 | +use Ramsey\Uuid\Uuid; |
| 16 | + |
| 17 | +final class SharedArchitectureTest |
| 18 | +{ |
| 19 | + public function test_shared_domain_should_not_import_from_outside(): Rule |
| 20 | + { |
| 21 | + return PHPat::rule() |
| 22 | + ->classes(Selector::inNamespace('CodelyTv\Shared\Domain')) |
| 23 | + ->canOnlyDependOn() |
| 24 | + ->classes(...array_merge(ArchitectureTest::languageClasses(), [ |
| 25 | + // Itself |
| 26 | + Selector::inNamespace('CodelyTv\Shared\Domain'), |
| 27 | + // Dependencies treated as domain |
| 28 | + Selector::classname(Uuid::class), |
| 29 | + ])) |
| 30 | + ->because('shared domain cannot import from outside'); |
| 31 | + } |
| 32 | + |
| 33 | + public function test_shared_infrastructure_should_not_import_from_other_contexts(): Rule |
| 34 | + { |
| 35 | + return PHPat::rule() |
| 36 | + ->classes(Selector::inNamespace('CodelyTv\Shared\Infrastructure')) |
| 37 | + ->shouldNotDependOn() |
| 38 | + ->classes(Selector::inNamespace('CodelyTv')) |
| 39 | + ->excluding( |
| 40 | + // Itself |
| 41 | + Selector::inNamespace('CodelyTv\Shared'), |
| 42 | + // This need to be refactored |
| 43 | + Selector::classname(MySqlDatabaseCleaner::class), |
| 44 | + Selector::classname(AuthenticateUserCommand::class), |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public function test_all_use_cases_can_only_have_one_public_method(): Rule |
| 49 | + { |
| 50 | + return PHPat::rule() |
| 51 | + ->classes( |
| 52 | + Selector::classname('/^CodelyTv\\\\.+\\\\.+\\\\Application\\\\.+\\\\(?!.*(?:Command|Query)$).*$/', true) |
| 53 | + ) |
| 54 | + ->excluding( |
| 55 | + Selector::implements(Response::class), |
| 56 | + Selector::implements(DomainEventSubscriber::class), |
| 57 | + Selector::inNamespace('/.*\\\\Tests\\\\.*/', true) |
| 58 | + ) |
| 59 | + ->shouldHaveOnlyOnePublicMethod(); |
| 60 | + } |
| 61 | +} |
0 commit comments