Laravel Testing
**Priority: P1 (HIGH)**
Universal anti-slop rules (identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps, shallow
assertions, coverage): anti-slop-rules.md. Only Laravel deltas
follow.
Stack Deltas
- Pest feature tests:
uses(RefreshDatabase::class)at the top of the file. Example:
it('creates a post', fn() => $this->postJson('/api/posts', [...])); the database rolled back after each test.
- Transactions:
DatabaseTransactionsfor faster but non-truncating isolation. - Service mocking (
[BE-TEST-04]):$this->mock(PaymentService::class)with
shouldReceive('charge')->once()->with(100); use $this->spy() for loose verification; never make real network calls.
- Factories & DB (
[BE-TEST-02]): create data viaPost::factory()->count(3)->create(['user_id' => $id]). In
phpunit.xml, set <env name='DB_CONNECTION' value='sqlite'/> and <env name='DB_DATABASE' value=':memory:'/>.
- HTTP assertions (
[BE-TEST-03]): chainassertStatus(201),assertJson(['data' => ...]),assertJsonStructure,
and assertHeader; never assert status alone.
- Coverage: diagnostic and project-configured; verify risk-weighted critical paths.
Anti-Patterns
- No real network calls: always mock or stub external services.
- No state leakage between tests: use
RefreshDatabase. - No raw inserts: never DB::table()->insert() test data; use Eloquent Factories.