ta-tikoma/phpunit-architecture-test
Architecture testing for PHP projects using PHPUnit. Define and enforce dependency, namespace, and layer rules (e.g., no forbidden coupling, keep domains isolated) and catch architectural violations in CI with fast, expressive tests.
composer require --dev ta-tikoma/phpunit-architecture-testTests\ArchitectureTest) that extends PHPUnit\Architecture\Steps\TestCase $this->expectNotTargetedNamespaces([]); $this->expectClasses()->beFinal(); to enforce rules like “all classes must be final”expectNamespaces(['App\\Domain\\', 'App\\Application\\'])->notToDependOnEachOther()expectClasses()->inNamespace('App\\Service')->toHaveMethod('handle')expectClasses()->inNamespace('App\\Infra\\Persistence')->toDependOnlyOn('App\\Domain') to guard against infra leaking into domainPHPUnit\Architecture\Rules\Rule for domain-specific patterns (e.g., “all DTOs must be immutable”)php artisan test --filter Architecture or include in CI pipeline via vendor/bin/phpunit --testsuite=Architecture->bootstrap() or group tests carefully to avoid ReflectionExceptionexpectClasses(), inNamespace(), and constraints in the correct order (e.g., inNamespace() must precede toHaveMethod())inNamespace('App') may match AppTest — use inNamespace('App\\') with trailing backslashsetUp() carefully — parent setup handles the AST analysis context; calling parent::setUp() is criticaldump() or dd() inside rules but avoid it in final tests; enable ->withDetails() to see why a rule failed#[ArchitectureIgnore]) when neededHow can I help you explore Laravel packages today?