test(architecture): update Application and Domain tests for readonly checks
Refactor tests to utilize enumsIn function for better maintainability.
This commit is contained in:
parent
382f181ced
commit
bbbeea6cde
2 changed files with 24 additions and 7 deletions
|
|
@ -4,6 +4,25 @@ declare(strict_types=1);
|
|||
|
||||
namespace Tests\Architecture;
|
||||
|
||||
/** @return array<int, string> */
|
||||
function enumsIn(string $namespace): array
|
||||
{
|
||||
$dir = dirname(__DIR__, 2) . '/src/' . str_replace('\\', '/', $namespace);
|
||||
$enums = [];
|
||||
if (! is_dir($dir)) {
|
||||
return $enums;
|
||||
}
|
||||
|
||||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)) as $file) {
|
||||
$class = $namespace . str_replace([$dir, '.php', '/'], ['', '', '\\'], $file->getPathname());
|
||||
if ($file->isFile() && enum_exists($class)) {
|
||||
$enums[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $enums;
|
||||
}
|
||||
|
||||
describe('Application Architecture Rules', function (): void {
|
||||
arch('Application layer does not depend on Presentation, Infra, or App')
|
||||
->expect('Application')
|
||||
|
|
@ -24,8 +43,10 @@ describe('Application Architecture Rules', function (): void {
|
|||
|
||||
arch('Application Usecase classes are final and readonly')
|
||||
->expect('Application\Usecase')
|
||||
->classes()
|
||||
->toBeReadonly()
|
||||
->toBeFinal();
|
||||
->toBeFinal()
|
||||
->ignoring(enumsIn('Application\Usecase'));
|
||||
|
||||
arch('Application layer must not contain Presenters')
|
||||
->expect('Application')
|
||||
|
|
|
|||
|
|
@ -50,12 +50,8 @@ describe('Domain Architecture Rules', function (): void {
|
|||
|
||||
arch('Domain Value Objects are readonly')
|
||||
->expect('Domain\Models\ValueObjects')
|
||||
->toBeReadonly()
|
||||
->ignoring([
|
||||
'Domain\Models\ValueObjects\Employees\EmployeeSortColumn',
|
||||
'Domain\Models\ValueObjects\Inco\PortionType',
|
||||
'Domain\Models\ValueObjects\IncoCompo\IncoCompoPartDto',
|
||||
]);
|
||||
->classes()
|
||||
->toBeReadonly();
|
||||
|
||||
arch('Domain exceptions extend native DomainException')
|
||||
->expect('Domain\Exceptions')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue