Write tests with Pest/PHPUnit, feature tests, unit tests, mocking, and factories. Use when testing controllers, services, models, or implementing TDD.
View on GitHubfusengine/agents
fuse-laravel
plugins/laravel-expert/skills/laravel-testing/SKILL.md
January 22, 2026
Select agents to install to:
npx add-skill https://github.com/fusengine/agents/blob/main/plugins/laravel-expert/skills/laravel-testing/SKILL.md -a claude-code --skill laravel-testingInstallation paths:
.claude/skills/laravel-testing/# Laravel Testing
## Documentation
### Testing
- [testing.md](docs/testing.md) - Testing basics
- [http-tests.md](docs/http-tests.md) - HTTP feature tests
- [database-testing.md](docs/database-testing.md) - Database testing
- [console-tests.md](docs/console-tests.md) - Console tests
- [mocking.md](docs/mocking.md) - Mocking & fakes
- [dusk.md](docs/dusk.md) - Browser testing
### Code Quality
- [pint.md](docs/pint.md) - Code style fixer
## Pest Feature Test
```php
<?php
declare(strict_types=1);
use App\Models\Post;
use App\Models\User;
describe('PostController', function () {
beforeEach(function () {
$this->user = User::factory()->create();
});
it('lists all posts', function () {
Post::factory()->count(3)->create();
$this->getJson('/api/v1/posts')
->assertOk()
->assertJsonCount(3, 'data');
});
it('creates a post when authenticated', function () {
$data = ['title' => 'Test', 'content' => 'Content', 'status' => 'draft'];
$this->actingAs($this->user)
->postJson('/api/v1/posts', $data)
->assertCreated()
->assertJsonPath('data.title', 'Test');
$this->assertDatabaseHas('posts', ['title' => 'Test']);
});
it('returns 401 for unauthenticated users', function () {
$this->postJson('/api/v1/posts', [])
->assertUnauthorized();
});
it('validates required fields', function () {
$this->actingAs($this->user)
->postJson('/api/v1/posts', [])
->assertUnprocessable()
->assertJsonValidationErrors(['title', 'content']);
});
});
```
## Unit Test with Mocking
```php
<?php
declare(strict_types=1);
use App\Services\PostService;
use App\Repositories\Contracts\PostRepositoryInterface;
describe('PostService', function () {
it('creates a post with valid data', function () {
$repository = Mockery::mock(PostRepositoryInterface::class);
$repository->sho