← ClaudeAtlas

phpunitlisted

PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests.
majiayu000/claude-skill-registry-data · ★ 3 · Testing & QA · score 57
Install: claude install-skill majiayu000/claude-skill-registry-data
**Name:** PHPUnit **Description:** PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests. **Compatible Agents:** general-purpose, testing **Tags:** tests/**/*.php, laravel, php, testing, phpunit, unit-test, feature-test ## Rules - **Feature tests** go in `tests/Feature/` and extend `Tests\TestCase` - **Unit tests** go in `tests/Unit/` and extend `PHPUnit\Framework\TestCase` - Always use `Illuminate\Foundation\Testing\RefreshDatabase` in feature tests that touch the database - Unit tests have no Laravel bootstrap — pure PHP tests only - Use `test_` method prefix with snake_case names: `test_user_can_create_resource` - All test methods must have `: void` return type - One assertion concern per test method — keep tests focused - Prefer `assertSame` over `assertEquals` for strict type + value comparison - Assert specific values, not just truthiness - Every new model **must** have a corresponding factory in `database/factories/` - Use factories in tests instead of manual `create()` / `insert()` calls - Define meaningful default factory values; use states for variations ## Examples ```php // Feature test use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class InvoiceControllerTest extends TestCase { use RefreshDatabase; public function test_user_can_create_invoice(): void { $user = User::factory()->create(); $order = Order::factory()->create(['user_id' => $user->id]); $