Development › Testing
Testing
Test from the inside out: Domain → Application → Infrastructure → Feature/API → Architecture.
#Suites
| Suite | Path | Focus |
|---|---|---|
| Unit | tests/Unit | Actions, domain rules, pure logic with fakes |
| Feature | tests/Feature | HTTP API, middleware, wiring |
| Architecture | tests/Architecture | Structural invariants (folders, DX commands) |
Run everything:
php artisan testRun a slice:
php artisan test --testsuite=Architecture
php artisan test tests/Unit/Application#Guidelines
- Unit-test Actions by faking
EventBus, repositories, and other contracts — no HTTP, no Kafka. - Feature-test APIs through Controllers; assert status codes, JSON shape, and side effects you own.
- Prefer SQLite
:memory:(already configured) for speed unless a test needs Postgres-specific SQL. - Use
QUEUE_CONNECTION=syncandCACHE_STORE=arrayin tests (phpunit env). - For Kafka, test the consumer handler with a fabricated
DomainEvent; integration tests against a broker are optional/CI-only.
#Example: Action unit test
class="tk-v">$action = new CreateOrder(class="tk-v">$fakeRepo, class="tk-v">$fakeEventBus);
class="tk-v">$order = class="tk-v">$action->execute(class="tk-v">$dto);
class="tk-c">// assert repo received DTO + event published#Architecture tests
tests/Architecture/ArchitectureTest.php asserts the enterprise root directories and DX command files exist. Extend it with package-level rules (e.g. Domain must not use Eloquent) as the codebase grows.