testing-laravel

Solid

Writes Laravel tests using PHPUnit. Use when "write tests", "add tests", "phpunit", "laravel test", "feature test", "unit test", "mock", "factory", or testing controllers, models, services, actions, jobs, artisan commands, or API endpoints.

Testing & QA 33 stars 3 forks Updated 3 days ago MIT

Install

View on GitHub

Quality Score: 82/100

Stars 20%
51
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Testing Laravel Use PHPUnit with Laravel's testing helpers. Every test file starts with `declare(strict_types=1)`. ## Test Classification - **Feature tests** (`tests/Feature/`): HTTP requests through the full stack — routes, controllers, middleware, validation, database. Use `$this->getJson()`, `$this->postJson()`, etc. - **Unit tests** (`tests/Unit/`): Isolated logic — services, actions, value objects, helpers. No HTTP, minimal database. Default to feature tests for anything touching routes, controllers, or models. Use unit tests for pure logic and action classes. ## Critical Rules - `use RefreshDatabase` trait in every test class that touches the database - Model factories for all test data — use factories instead of raw `DB::table()` inserts - One behavior per test method. Name with `test_` prefix: `test_user_can_update_own_profile` - Assert both response status AND side effects (DB state, dispatched jobs, sent notifications) - `actingAs($user)` for auth — use this instead of manually setting sessions or tokens - `postJson()` / `getJson()` for API endpoints — sets proper Accept headers and returns JSON assertions - Fake facades BEFORE the action: `Queue::fake()` then act then `Queue::assertPushed(...)` - `assertDatabaseHas` / `assertDatabaseMissing` to verify persistence — use these instead of re-querying - Resolve action classes from the container with `resolve()` so DI works; use `swap()` to inject mocks - **Tests expose bugs, not the reverse**: If a test uncover...

Details

Author
iliaal
Repository
iliaal/whetstone
Created
6 months ago
Last Updated
3 days ago
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category