Pest Plugin Laravel
repository·5.x·Indexed 42 days ago
https://github.com/pestphp/pest-plugin-laravelA 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.
What's inside Pest Laravel
- 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.
Create a new test file with `pest:test`
5.xThe
pest:testcommand 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.phpextension and ensures the file is correctly named.
Options
--unit: Creates a Unit test (placed in thetests/Unitdirectory).--dusk: Creates a Dusk (Browser) test (placed in thetests/Browserdirectory).--test-directory=tests: Specifies the base directory for tests. Defaults totests.--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 --forceRun Dusk tests with the pest:dusk command
5.xThe
pest:duskcommand 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-ttyCreate a new dataset file with pest:dataset
5.xUse the
pest:datasetcommand to scaffold a new Pest dataset file. This command creates a PHP file in yourDatasetsdirectory 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 totests).
php artisan pest:dataset users --test-directory=tests