test(architecture): update Application and Domain tests for readonly checks

Refactor tests to utilize enumsIn function for better maintainability.
This commit is contained in:
Jérémy Munsch 2026-08-14 11:33:29 +02:00
parent 382f181ced
commit bbbeea6cde
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
2 changed files with 24 additions and 7 deletions

View file

@ -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')

View file

@ -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')