Console tests
Laravel lets you write concise tests for Artisan commands that include input and output.This page is aligned with Laravel’s latest console testing API and also covers
expectsSearch for verifying Laravel Prompts search inputs.Introduction
Use theartisan method to run the command and chain expectations to verify it.
- Pest
- PHPUnit
Success / failure assertions
You can verify the command’s success or failure by checking the exit status.Input / output expectations
Input expectations
You can mock user interactions for question prompts and search inputs.Output expectations
You can verify exact matches, partial matches, or table output.Confirmation expectations
For yes/no confirmation prompts, useexpectsConfirmation.
Console events
By default,CommandStarting and CommandFinished are not fired during tests.
Add WithConsoleEvents to test classes that need to verify these events.