first commit
This commit is contained in:
54
tests/Architecture/KernelStructureTest.php
Normal file
54
tests/Architecture/KernelStructureTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user