update project
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Architecture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
final class Phase2BoundaryArchitectureTest extends TestCase
|
||||
{
|
||||
public function test_school_core_does_not_import_extension_namespace(): void
|
||||
{
|
||||
$violations = $this->scan(app_path('Domain/SchoolCore'), ['App\\Domain\\IslamicSundaySchool']);
|
||||
$this->assertSame([], $violations);
|
||||
}
|
||||
|
||||
public function test_domain_services_do_not_accept_raw_request_or_call_auth(): void
|
||||
{
|
||||
$violations = $this->scan(app_path('Domain'), ['Illuminate\\Http\\Request', 'auth()']);
|
||||
$violations = array_values(array_filter($violations, fn (string $path): bool => ! str_contains($path, 'SchoolContextResolver.php')));
|
||||
$this->assertSame([], $violations);
|
||||
}
|
||||
|
||||
public function test_core_contracts_keep_neutral_vocabulary(): void
|
||||
{
|
||||
$violations = $this->scan(app_path('Domain/SchoolCore/Contracts'), ['masjid', 'ministry', 'bible', 'servant', 'service_day']);
|
||||
$this->assertSame([], $violations);
|
||||
}
|
||||
|
||||
/** @param array<int, string> $needles @return array<int, string> */
|
||||
private function scan(string $root, array $needles): array
|
||||
{
|
||||
if (! is_dir($root)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$violations = [];
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root)) as $file) {
|
||||
if (! $file instanceof SplFileInfo || $file->getExtension() !== 'php') {
|
||||
continue;
|
||||
}
|
||||
$contents = file_get_contents($file->getPathname()) ?: '';
|
||||
foreach ($needles as $needle) {
|
||||
if (str_contains($contents, $needle)) {
|
||||
$violations[] = $file->getPathname() . ' contains ' . $needle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $violations;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user