<< All versions
Skill v1.0.1
currentAutomated scan100/100diegosouzapw/awesome-omni-skill/phpunit
1 files
──Details
PublishedMay 14, 2026 at 11:38 PM
Content Hashsha256:0b406a3838d2a376...
Git SHAa6b3c3005ced
Bump Typepatch
──Files
Files (1 file, 3.1 KB)
SKILL.md3.1 KBactive
SKILL.md · 96 lines · 3.1 KB
version: "1.0.1" name: phpunit description: PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests.
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 extendTests\TestCase - Unit tests go in
tests/Unit/and extendPHPUnit\Framework\TestCase - Always use
Illuminate\Foundation\Testing\RefreshDatabasein 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
: voidreturn type - One assertion concern per test method — keep tests focused
- Prefer
assertSameoverassertEqualsfor 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 testuse 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]);$response = $this->actingAs($user)->postJson('/api/invoices', ['order_id' => $order->id]);$response->assertStatus(201);$this->assertDatabaseHas('invoices', ['order_id' => $order->id]);}}
php
// Unit test — no Laravel bootstrapuse PHPUnit\Framework\TestCase;class MoneyHelperTest extends TestCase{public function test_formats_amount_in_cents_as_currency_string(): void{$result = MoneyHelper::format(1000, 'CHF');$this->assertSame('10.00 CHF', $result);}}
php
// Factory with states// database/factories/UserFactory.phppublic function unverified(): static{return $this->state(fn (array $attributes) => ['email_verified_at' => null,]);}// Usage in testsUser::factory()->create();User::factory()->unverified()->create();
Anti-Patterns
- Not using
RefreshDatabasein feature tests that write to the database - Using raw
insert()orcreate()calls in tests instead of factories - Mixing multiple assertion concerns in a single test method
- Using
assertEqualswhenassertSameis needed for strict comparison - Asserting truthiness (
assertTrue($result !== null)) instead of a specific value - Unit tests that bootstrap the full Laravel application (use
Tests\TestCaseonly for feature tests)
References
- PHPUnit Documentation
- Laravel Testing
- Related:
PestTesting/SKILL.md— the preferred test framework (Pest over raw PHPUnit)