zenstruck/console-test
Test your Symfony Console commands with ease. zenstruck/console-test provides a lightweight harness to run commands, feed input, capture output, and assert exit codes and messages—ideal for fast, reliable unit/integration tests without booting full apps.
Install via Composer: composer require --dev zenstruck/console-test. No extra service provider setup needed—it auto-registers with Laravel/Symfony. Start by writing a PHPUnit test that extends Zenstruck\Console\Test\CommandTestCase (Laravel) or uses the trait Zenstruck\Console\Test\WithConsoleCommands. Your first test should run a real command (e.g., php artisan your:command) using $this->run('your:command', ['arg' => 'value']), then assert exit code (assertSuccess()) and output (assertOutputContains('Success!')). This is your entry point to safe, reliable CLI testing.
$this->run('cmd:name', $args, $options) with chained assertions for output, exit code, and error output. Use assertExitCode(0) for success, assertOutputContains('foo') for partial matches, or assertOutputMatches('/pattern/') for regex.withInput(['yes', 'john']) before run(), or use withInputs([...]) for multi-step prompts.assertMigrateRunsSuccessfully() to reduce duplication across test suites.run() inside each test—commands execute in full isolation, with a fresh container each time (critical for state-sensitive commands).dumpOutput(), dumpErrorOutput(), or getOutput()/getErrorOutput() to inspect raw output when assertions fail.dump() calls from nested services to appear in CLI output. Use Laravel’s dd()/dump() in tests to debug.ask(), confirm()) require withInput() before run(). If questions appear skipped, verify interactive mode isn’t enabled—run() defaults to non-interactive; use withInteractive(true) only when testing full interactive flows.php artisan config:clear—cached configs may override environment variables during command execution.app/Console/Kernel.php and not conditionally resolved via service location (which may break auto-discovery in tests).CommandTester via getCommandTester() after run() for low-level control (e.g., inspecting output formatting, raw input parameters), but prefer built-in assertions for readability.How can I help you explore Laravel packages today?