55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Architecture;
|
|
|
|
use Tests\Architecture\Support\ArchitectureTestCase;
|
|
|
|
final class KernelStructureTest extends ArchitectureTestCase
|
|
{
|
|
public function testKernelUsesOnlyApprovedTopLevelEntries(): void
|
|
{
|
|
$sharedPath = $this->projectPath('src/Kernel');
|
|
self::assertDirectoryExists($sharedPath);
|
|
|
|
$entries = array_values(array_filter(scandir($sharedPath) ?: [], static fn (string $entry): bool => !in_array($entry, ['.', '..'], true)));
|
|
sort($entries);
|
|
|
|
self::assertSame([
|
|
'Html',
|
|
'Http',
|
|
'Mail',
|
|
'Pagination',
|
|
'Persistence',
|
|
'Runtime',
|
|
'Support',
|
|
], $entries, 'Kernel must expose only approved transverse modules at top level.');
|
|
}
|
|
|
|
public function testKernelPathsDoNotUseFeatureModuleNames(): void
|
|
{
|
|
$sharedPath = $this->projectPath('src/Kernel');
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
new \RecursiveDirectoryIterator($sharedPath, \FilesystemIterator::SKIP_DOTS),
|
|
\RecursiveIteratorIterator::SELF_FIRST,
|
|
);
|
|
|
|
foreach ($iterator as $fileInfo) {
|
|
$relativePath = substr($fileInfo->getPathname(), strlen($sharedPath) + 1);
|
|
$pathSegments = preg_split('~/+~', $relativePath) ?: [];
|
|
|
|
foreach ($pathSegments as $segment) {
|
|
$name = pathinfo($segment, PATHINFO_FILENAME);
|
|
|
|
foreach (self::FEATURE_MODULES as $module) {
|
|
self::assertFalse(
|
|
str_starts_with($name, $module),
|
|
sprintf('Kernel should not host feature-specific files or directories: %s', 'src/Kernel/' . $relativePath),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|