一键导入
phpunit
PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Readonly data containers with typed factory methods (`fromArray`, `fromModel`, `fromCollection`, `fromRequest`) used to pass structured data between application layers — especially for external API responses, Eloquent models, and service boundaries. Use this skill whenever creating, reviewing, or refactoring DTOs, Data Transfer Objects, value objects for inter-layer communication, or mapping payloads from APIs, models, or collections into typed PHP objects. Also trigger when the user mentions spatie/laravel-data alternatives, data mapping, or payload normalization in a Laravel context.
Eloquent model conventions for mass assignment, casts, relationship naming, activity logging, and mandatory model tests (CRUD + relations).
Single-purpose business logic classes that encapsulate one well-defined business operation. Actions are the primary location for business logic in Laravel applications, invoked from controllers, commands, or jobs.
Albatros accounting API integration via Saloon. Use when working with app/Services/Albatros/, AlbatrosConnector, or Albatros DTOs.
Laravel Blade template conventions covering components, output escaping, security, structure, and formatting.
Artisan console command classes that serve as the CLI entry point for operations. Commands validate input and delegate all business logic to Actions or Services.
| name | phpunit |
| description | PHPUnit test structure, naming, assertions, and factory conventions for Laravel feature and unit tests. |
| compatible_agents | ["test","refactor","review"] |
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)