Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pest Plugin Laravel Laravel Package

pestphp/pest-plugin-laravel

Pest Plugin for Laravel adds Laravel-specific testing helpers and integration to Pest, making it easy to write expressive, fast tests for Laravel apps while leveraging the familiar Laravel testing ecosystem.

View on GitHub
Deep Wiki
Context7

Getting Started

Install Pest and the Laravel plugin via Composer:

composer require --dev pestphp/pest pestphp/pest-plugin-laravel

Run php artisan test:make --pest to generate Pest-style tests (e.g., tests/Feature/UserTest.php). Begin with simple feature tests using Laravel’s built-in testing helpers — the plugin auto-registers Laravel’s test traits like RefreshDatabase, WithoutMiddleware, and InteractsWithAuthentication by default. Your first test might look like:

it('shows the homepage', function () {
    $response = $this->get('/');
    $response->assertStatus(200);
});

Check phpunit.xml — the plugin populates this with Pest configuration, and tests live in tests/ with Feature and Unit subdirectories.

Implementation Patterns

  • Laravel-Specific Assertions & Helpers: Use actingAs(), getJson(), postJson(), refreshDatabase(), and assertions like assertJsonPath() directly. The plugin patches these via TestCase enhancements.
  • Factories & Seeds: Works seamlessly with Database\Factories — call User::factory()->create() and chain database assertions.
  • Parallel Testing: If using parallel in phpunit.xml, the plugin intelligently handles database isolation using per-process databases (requires RefreshDatabase and parallel support).
  • Custom Test Generators: Extend Pest’s make:test command with custom stubs in stubs/test.php — it respects Laravel conventions (e.g., test_create_userUserTest.php).
  • Integration with Pest’s DSL: Combine it(), test(), and describe() blocks with Laravel’s testing context — e.g.:
describe('user registration', function () {
    beforeEach(fn () => $this->withoutMiddleware());
    
    it('creates a new user', function () {
        $user = User::factory()->make();
        $this->post('/register', $user->toArray());
        $this->assertDatabaseHas('users', ['email' => $user->email]);
    });
});

Gotchas and Tips

  • Trait Conflicts: Avoid mixing PHPUnit’s TestCase directly — Pest tests should extend Pest\Laravel\TestCase implicitly. Don’t manually use TestCase; let Pest handle it.
  • Middleware Interference: If routes require auth or CSRF, use $this->withoutMiddleware() or $this->withMiddleware() explicitly — forgetting this causes 302 redirects instead of 200.
  • Database Refreshing Overhead: RefreshDatabase is great, but for large suites, consider DatabaseTransactions for speed (especially in unit tests where full isolation isn’t needed).
  • Environment Variables: Tests inherit .env.testing, but php artisan test now respects --env and .env.test — ensure your test .env is configured (e.g., DB_CONNECTION=sqlite, DB_DATABASE=:memory:).
  • Extension Points: The plugin integrates with Pest’s plugin system — check Pest\Laravel\ServiceProvider if you need to override default behaviors or add custom macros. contributed to by laravel-tests, not the core Pest package, so keep both updated.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport