An architecture test that asserts on namespaces

A layering rule that exists only in a diagram is a rule that has already been broken, and asserting on it is a test like any other.

public function testTheDomainDoesNotDependOnTheFramework(): void
{
    $violations = [];

    foreach ($this->filesIn('src/Domain') as $file) {
        foreach ($this->importsIn($file) as $import) {
            if (strpos($import, 'Illuminate\') === 0) {
                $violations[] = "{$file}: {$import}";
            }
        }
    }

    $this->assertSame([], $violations, implode("n", $violations));
}

Fifteen lines of reflection or a regex over the imports is enough for the common case, and a dedicated tool such as Deptrac is better once there are more than two rules. Starting with a baseline of existing violations and forbidding new ones is the tractable path on a codebase that has never had this — the same ratchet as a static analysis baseline. A violation becomes a failed build rather than a review comment somebody may or may not make.