codeception/module-cli
Codeception CLI module for running and testing command-line applications. Provides helpers to execute commands, capture output, check exit codes, and assert on stdout/stderr, making it easy to write automated CLI tests within your Codeception suite.
Start by installing via Composer: composer require --dev codeception/module-cli. Then enable it in your codeception.yml or suite config (e.g., tests/unit.suite.yml) under modules: enabled: [CLI]. The module provides a cli actor method to run console commands during tests — ideal for testing Symfony Console, Laravel Artisan, or generic CLI scripts. Your first use case: verify an Artisan command’s output and exit code by calling $I->runCommand('list', ['--format' => 'json']) and asserting on $I->seeInOutput('"name":"...') or $I->assertCommandIsSuccessful().
$I->runCommand($command, $arguments = [], $options = [], $input = null) to simulate CLI invocations. Pass arguments and options like a real CLI call — e.g., ['--env' => 'testing'].seeInOutput(), dontSeeInOutput(), grabFromOutput(), and seeInThisOutput() to inspect stdout/stderr separately using grabOutput() or grabErrorOutput().assertCommandIsSuccessful(), assertCommandFailed(), or seeExitCodeIs($code) for deterministic validation of command results.Codeception\Module\Laravel to access app state before/after commands. Use $I->runCommand('cache:clear') in acceptance or functional suites to validate side effects (e.g., cleared cache files).$input as 4th argument to simulate interactive prompts (e.g., yes\n for confirmation questions).$I->runCommand(..., [], [], null, $cwd = '/custom/path') if needed.['APP_ENV' => 'testing'] in the 5th argument (env parameter) of runCommand().$I->wait(0.1) or switch to grabOutput() with a custom assertion.seeExitCodeIs(0) with output checks — commands may succeed silently (e.g., echo '' > /dev/null).ask()) often fail. Use echo "answer\n" | php artisan ... simulation or stub dependencies via Codeception dependency injection instead.Codeception\Module\CLI to wrap project-specific command runners (e.g., runMigrations(), seedDatabase()).How can I help you explore Laravel packages today?