99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
|
|
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')
|
|
->not->toUse([
|
|
'Presentation',
|
|
'Infra',
|
|
'Infrastructure',
|
|
'App',
|
|
]);
|
|
|
|
arch('Application layer does not depend on Illuminate or Symfony frameworks')
|
|
->expect('Application')
|
|
->not->toUse([
|
|
'Illuminate',
|
|
'Symfony',
|
|
]);
|
|
|
|
arch('Application layer does not use Laravel helper functions')
|
|
->expect('Application')
|
|
->not->toUse([
|
|
'abort',
|
|
'app',
|
|
'auth',
|
|
'asset',
|
|
'back',
|
|
'bcrypt',
|
|
'broadcast',
|
|
'cache',
|
|
'config',
|
|
'cookie',
|
|
'csrf_token',
|
|
'dd',
|
|
'dump',
|
|
'decrypt',
|
|
'dispatch',
|
|
'event',
|
|
'factory',
|
|
'logger',
|
|
'redirect',
|
|
'request',
|
|
'response',
|
|
'route',
|
|
'session',
|
|
'storage',
|
|
'url',
|
|
'throw_if',
|
|
'throw_unless',
|
|
'__',
|
|
'trans',
|
|
'trans_choice',
|
|
'view',
|
|
]);
|
|
|
|
arch('Application layer uses strict types')
|
|
->expect('Application')
|
|
->toUseStrictTypes();
|
|
|
|
arch('Application Usecase classes are final and readonly')
|
|
->expect('Application\Usecase')
|
|
->classes()
|
|
->toBeReadonly()
|
|
->toBeFinal()
|
|
->ignoring(enumsIn('Application\Usecase'));
|
|
|
|
arch('Application layer must not contain Presenters')
|
|
->expect('Application')
|
|
->classes()
|
|
->not->toHaveSuffix('Presenter');
|
|
|
|
arch('Application layer must not contain Views')
|
|
->expect('Application')
|
|
->classes()
|
|
->not->toHaveSuffix('View');
|
|
});
|