resources/boost/skills/phpunit/SKILL.md
PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests.
npx skillsauth add codebar-ag/coding-guidelines phpunitInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
phpunit.xml / phpunit.xml.dist is present and configured for this project.tests/Unit) vs feature (tests/Feature).RefreshDatabase in feature tests that modify/query DB state.assertSame) when type and value matter.Tests\TestCase; unit tests extend PHPUnit\Framework\TestCase.test_ snake_case method names and : void return types.// 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]);
$response = $this->actingAs($user)
->postJson('/api/invoices', ['order_id' => $order->id]);
$response->assertStatus(201);
$this->assertDatabaseHas('invoices', ['order_id' => $order->id]);
}
}
// Unit test — no Laravel bootstrap
use 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);
}
}
// Factory with states
// database/factories/UserFactory.php
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
// Usage in tests
User::factory()->create();
User::factory()->unverified()->create();
# Full Laravel test run (recommended entrypoint)
php artisan test
# Run PHPUnit directly
vendor/bin/phpunit
# Run a single file
vendor/bin/phpunit tests/Feature/InvoiceControllerTest.php
# Filter by test method name
vendor/bin/phpunit --filter=test_user_can_create_invoice
RefreshDatabase in feature tests that write to the databaseinsert() or create() calls in tests instead of factoriesassertEquals when assertSame is needed for strict comparisonassertTrue($result !== null)) instead of a specific valueTests\TestCase only for feature tests)PestTesting/SKILL.md — the preferred test framework (Pest over raw PHPUnit)testing
Translation and localization conventions for Laravel. Use when adding user-facing strings, creating translation files, or working with lang/ directory.
tools
Reusable behaviour shared across multiple unrelated classes. Traits provide shared Eloquent scopes, accessors, lifecycle hooks, and small stateless helper methods.
development
Tailwind CSS v4 styling conventions. Use when working with CSS, Tailwind utilities, or customizing the theme in Laravel projects.
development
Orchestration classes that coordinate multiple Actions, external APIs, or domain operations into a cohesive workflow. Services own transaction boundaries and third-party API integrations.