-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(phpat): install codely fork * chore(phpat): test shared domain architecture * ci: test architecture * chore(phpat): test shared infrastructure architecture * chore(phpat): test shared infrastructure architecture * chore(phpat): test application services only have one public method
- Loading branch information
1 parent
ff40d42
commit 0e52a8b
Showing
10 changed files
with
275 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
includes: | ||
- vendor/phpat/phpat/extension.neon | ||
|
||
parameters: | ||
level: 0 | ||
paths: | ||
- ./apps | ||
- ./src | ||
- ./tests | ||
excludePaths: | ||
- ./apps/backoffice/backend/var | ||
- ./apps/backoffice/frontend/var | ||
- ./apps/mooc/backend/var | ||
- ./apps/mooc/frontend/var | ||
|
||
services: | ||
- | ||
class: CodelyTv\Tests\Shared\SharedArchitectureTest | ||
tags: | ||
- phpat.test | ||
|
||
- | ||
class: CodelyTv\Tests\Mooc\MoocArchitectureTest | ||
tags: | ||
- phpat.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CodelyTv\Tests\Mooc; | ||
|
||
use CodelyTv\Tests\Shared\Infrastructure\ArchitectureTest; | ||
use PHPat\Selector\Selector; | ||
use PHPat\Test\Builder\Rule; | ||
use PHPat\Test\PHPat; | ||
|
||
final class MoocArchitectureTest | ||
{ | ||
public function test_mooc_domain_should_only_import_itself_and_shared(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes(Selector::inNamespace('/^CodelyTv\\\\Mooc\\\\.+\\\\Domain/', true)) | ||
->canOnlyDependOn() | ||
->classes(...array_merge(ArchitectureTest::languageClasses(), [ | ||
// Itself | ||
Selector::inNamespace('/^CodelyTv\\\\Mooc\\\\.+\\\\Domain/', true), | ||
// Shared | ||
Selector::inNamespace('CodelyTv\Shared\Domain'), | ||
])) | ||
->because('mooc domain can only import itself and shared domain'); | ||
} | ||
|
||
public function test_mooc_application_should_only_import_itself_and_domain(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes(Selector::inNamespace('/^CodelyTv\\\\Mooc\\\\.+\\\\Application/', true)) | ||
->canOnlyDependOn() | ||
->classes(...array_merge(ArchitectureTest::languageClasses(), [ | ||
// Itself | ||
Selector::inNamespace('/^CodelyTv\\\\Mooc\\\\.+\\\\Application/', true), | ||
Selector::inNamespace('/^CodelyTv\\\\Mooc\\\\.+\\\\Domain/', true), | ||
// Shared | ||
Selector::inNamespace('CodelyTv\Shared'), | ||
])) | ||
->because('mooc application can only import itself and shared'); | ||
} | ||
|
||
public function test_mooc_infrastructure_should_not_import_other_contexts_beside_shared(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes(Selector::inNamespace('CodelyTv\Mooc')) | ||
->shouldNotDependOn() | ||
->classes(Selector::inNamespace('CodelyTv')) | ||
->excluding( | ||
// Itself | ||
Selector::inNamespace('CodelyTv\Mooc'), | ||
// Shared | ||
Selector::inNamespace('CodelyTv\Shared'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CodelyTv\Tests\Shared\Infrastructure; | ||
|
||
use ArrayIterator; | ||
use BackedEnum; | ||
use Countable; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use DomainException; | ||
use InvalidArgumentException; | ||
use IteratorAggregate; | ||
use PHPat\Selector\Selector; | ||
use RuntimeException; | ||
use Stringable; | ||
use Throwable; | ||
use Traversable; | ||
|
||
final class ArchitectureTest | ||
{ | ||
public static function languageClasses(): array | ||
{ | ||
return [ | ||
Selector::classname(Throwable::class), | ||
Selector::classname(InvalidArgumentException::class), | ||
Selector::classname(RuntimeException::class), | ||
Selector::classname(DateTimeImmutable::class), | ||
Selector::classname(DateTimeInterface::class), | ||
Selector::classname(DomainException::class), | ||
Selector::classname(Stringable::class), | ||
Selector::classname(BackedEnum::class), | ||
Selector::classname(Countable::class), | ||
Selector::classname(IteratorAggregate::class), | ||
Selector::classname(Traversable::class), | ||
Selector::classname(ArrayIterator::class), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CodelyTv\Tests\Shared; | ||
|
||
use CodelyTv\Backoffice\Auth\Application\Authenticate\AuthenticateUserCommand; | ||
use CodelyTv\Shared\Domain\Bus\Event\DomainEventSubscriber; | ||
use CodelyTv\Shared\Domain\Bus\Query\Response; | ||
use CodelyTv\Tests\Shared\Infrastructure\ArchitectureTest; | ||
use CodelyTv\Tests\Shared\Infrastructure\Doctrine\MySqlDatabaseCleaner; | ||
use PHPat\Selector\Selector; | ||
use PHPat\Test\Builder\Rule; | ||
use PHPat\Test\PHPat; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
final class SharedArchitectureTest | ||
{ | ||
public function test_shared_domain_should_not_import_from_outside(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes(Selector::inNamespace('CodelyTv\Shared\Domain')) | ||
->canOnlyDependOn() | ||
->classes(...array_merge(ArchitectureTest::languageClasses(), [ | ||
// Itself | ||
Selector::inNamespace('CodelyTv\Shared\Domain'), | ||
// Dependencies treated as domain | ||
Selector::classname(Uuid::class), | ||
])) | ||
->because('shared domain cannot import from outside'); | ||
} | ||
|
||
public function test_shared_infrastructure_should_not_import_from_other_contexts(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes(Selector::inNamespace('CodelyTv\Shared\Infrastructure')) | ||
->shouldNotDependOn() | ||
->classes(Selector::inNamespace('CodelyTv')) | ||
->excluding( | ||
// Itself | ||
Selector::inNamespace('CodelyTv\Shared'), | ||
// This need to be refactored | ||
Selector::classname(MySqlDatabaseCleaner::class), | ||
Selector::classname(AuthenticateUserCommand::class), | ||
); | ||
} | ||
|
||
public function test_all_use_cases_can_only_have_one_public_method(): Rule | ||
{ | ||
return PHPat::rule() | ||
->classes( | ||
Selector::classname('/^CodelyTv\\\\.+\\\\.+\\\\Application\\\\.+\\\\(?!.*(?:Command|Query)$).*$/', true) | ||
) | ||
->excluding( | ||
Selector::implements(Response::class), | ||
Selector::implements(DomainEventSubscriber::class), | ||
Selector::inNamespace('/.*\\\\Tests\\\\.*/', true) | ||
) | ||
->shouldHaveOnlyOnePublicMethod(); | ||
} | ||
} |