Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Module Cli Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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().

Implementation Patterns

  • Command Testing Workflow: Use $I->runCommand($command, $arguments = [], $options = [], $input = null) to simulate CLI invocations. Pass arguments and options like a real CLI call — e.g., ['--env' => 'testing'].
  • Output Assertions: Leverage methods like seeInOutput(), dontSeeInOutput(), grabFromOutput(), and seeInThisOutput() to inspect stdout/stderr separately using grabOutput() or grabErrorOutput().
  • Exit Code Validation: Combine assertCommandIsSuccessful(), assertCommandFailed(), or seeExitCodeIs($code) for deterministic validation of command results.
  • Integration in Laravel: Perfect for testing custom Artisan commands — pair with 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).
  • Mocking Input/Stdin: Pass $input as 4th argument to simulate interactive prompts (e.g., yes\n for confirmation questions).

Gotchas and Tips

  • Working Directory: The module runs commands in the project root by default. Override with $I->runCommand(..., [], [], null, $cwd = '/custom/path') if needed.
  • Environment Variables: CLI modules may inherit from the test runner’s env. To isolate tests, set env vars inline: ['APP_ENV' => 'testing'] in the 5th argument (env parameter) of runCommand().
  • Output Buffering Quirks: Some frameworks (e.g., Laravel) flush output asynchronously. If assertions miss output, add $I->wait(0.1) or switch to grabOutput() with a custom assertion.
  • Exit Code 0 ≠ Success: Always pair seeExitCodeIs(0) with output checks — commands may succeed silently (e.g., echo '' > /dev/null).
  • No Real TTY: Interactive commands expecting stdin/TTY (e.g., ask()) often fail. Use echo "answer\n" | php artisan ... simulation or stub dependencies via Codeception dependency injection instead.
  • Extension Point: The module is thin and not actively expanded. For advanced mocking, consider extending Codeception\Module\CLI to wrap project-specific command runners (e.g., runMigrations(), seedDatabase()).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation