Loading...
Loading...
Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.
npx skill4agent add asyrafhussin/agent-skills laravel-testingSupports both Pest PHP 4 and PHPUnit 12. See Framework Detection below.PHPUnit version note: Laravel 13 ships within its defaultphpunit/phpunit: ^12.5.12. All patterns in this skill are compatible with PHPUnit 11, 12, and 13.composer.json
# Look for these in require-dev:
# "pestphp/pest" → Pest
# "phpunit/phpunit" (without pest) → PHPUnitpestphp/pestphpunit/phpunittests/Pest.php"I couldn't detect the testing framework. Does this project use Pest PHP or PHPUnit?"
| Pest | PHPUnit | |
|---|---|---|
| Test function | | |
| Readable name | | |
| Grouping | | Test class name / nested classes |
| Trait application | | |
| Before each | | |
| After each | | |
| Parameterised | | |
| Global setup | | Base |
assertStatusassertJsonassertJsonPathassertDatabaseHasassertModelExistsactingAsMail::fake()Queue::fake()Event::fake()Notification::fake()Storage::fake()| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | HTTP & Feature Tests | CRITICAL | |
| 2 | Model Factories | CRITICAL | |
| 3 | Database Assertions | HIGH | |
| 4 | Faking Services | HIGH | |
| 5 | Authentication Testing | HIGH | |
| 6 | Test Organisation Patterns | MEDIUM | |
http-test-structurehttp-assert-responsehttp-assert-json-fluenthttp-refresh-databasefactory-definefactory-statesfactory-sequencesfactory-relationshipsdb-assert-hasdb-assert-missingdb-assert-soft-deletesfake-mailfake-queuefake-notificationfake-eventfake-storagefake-ai-agentfake-ai-mediafake-ai-dataauth-acting-asauth-sanctumpest-describe-itpest-datasetspest-hooks<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('authenticated user can create a post', function () {
$user = User::factory()->create();
$this->actingAs($user)
->postJson('/api/posts', ['title' => 'Hello World', 'body' => 'Content.'])
->assertStatus(201)
->assertJsonPath('data.title', 'Hello World');
$this->assertDatabaseHas('posts', ['title' => 'Hello World', 'user_id' => $user->id]);
});<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PostControllerTest extends TestCase
{
use RefreshDatabase;
public function test_authenticated_user_can_create_a_post(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->postJson('/api/posts', ['title' => 'Hello World', 'body' => 'Content.'])
->assertStatus(201)
->assertJsonPath('data.title', 'Hello World');
$this->assertDatabaseHas('posts', ['title' => 'Hello World', 'user_id' => $user->id]);
}
}AGENTS.md