Pest Plugin Laravel

repository·5.x·Indexed 42 days ago

https://github.com/pestphp/pest-plugin-laravel

A plugin for the Pest testing framework that provides specialized utilities and helpers for Laravel applications, including Artisan commands like pest:test for scaffolding tests, pest:dataset for creating dataset files, and pest:dusk for running browser tests.

Tokens
789
Snippets
3
Records
4
Agent score
4%

What's inside Pest Laravel

  1. Install the Pest Plugin Laravel

    5.x
    The Pest Plugin Laravel provides Laravel-specific testing utilities for the Pest testing framework. To begin testing your Laravel application with Pest, you should first visit the main Pest repository to ensure the core framework is installed, then add this plugin to your project.
  2. Create a new test file with `pest:test`

    5.x

    The pest:test command allows you to scaffold new Pest test files within your Laravel application. It automatically determines the test type (Feature, Unit, or Dusk) and places the file in the appropriate directory. If you do not provide a name, the command will interactively prompt you for one and then ask you to select the test type.

    Usage

    Run the command via Artisan:

    php artisan pest:test {name} [options]

    Arguments

    • name: The name of the test file (e.g., UserTest). The command handles the .php extension and ensures the file is correctly named.

    Options

    • --unit: Creates a Unit test (placed in the tests/Unit directory).
    • --dusk: Creates a Dusk (Browser) test (placed in the tests/Browser directory).
    • --test-directory=tests: Specifies the base directory for tests. Defaults to tests.
    • --force: Overwrites the existing test file if a file with the same name already exists.
    # Create a feature test
    php artisan pest:test UserTest
    
    # Create a unit test
    php artisan pest:test UserTest --unit
    
    # Create a Dusk test in a custom directory
    php artisan pest:test UserTest --dusk --test-directory=custom_tests
    
    # Overwrite an existing test
    php artisan pest:test UserTest --force
  3. Run Dusk tests with the pest:dusk command

    5.x

    The pest:dusk command allows you to run Laravel Dusk browser tests using the Pest testing framework. It extends the standard Dusk command functionality to integrate with Pest's runner.

    Options

    • --browse: Opens a visible browser window instead of running in headless mode. This is useful for debugging test interactions visually.
    • --without-tty: Disables output to the TTY (Teletypewriter), which can be useful in certain CI environments or when piping output.
    pest:dusk
    
    # To run with a visible browser:
    pest:dusk --browse
    
    # To disable TTY output:
    pest:dusk --without-tty
  4. Create a new dataset file with pest:dataset

    5.x

    Use the pest:dataset command to scaffold a new Pest dataset file. This command creates a PHP file in your Datasets directory containing a stub implementation. It automatically handles directory creation and replaces placeholders for the dataset name and its singular element name.

    Arguments:

    • name: The name of the dataset to create.

    Options:

    • --test-directory=tests: Specifies the name of your tests directory (defaults to tests).
    php artisan pest:dataset users --test-directory=tests