spryker / console
Console module
Installs: 2 632 180
Dependents: 22
Suggesters: 1
Security: 0
Stars: 0
Watchers: 8
Forks: 1
pkg:composer/spryker/console
Requires
- php: >=8.3
- spryker/acl-entity-extension: ^0.1.0 || ^0.2.0 || ^1.0.0
- spryker/application: ^3.37.0
- spryker/application-extension: ^1.0.0
- spryker/config: ^3.0.0
- spryker/container: ^1.4.0
- spryker/error-handler: ^2.0.0
- spryker/kernel: ^3.52.0
Requires (Dev)
- spryker/code-sniffer: *
- spryker/log: ^3.0.0
- spryker/propel: *
- spryker/testify: *
Suggests
- spryker/log: If you want to use the Log feature in console commands, install this package and add ConsoleLogPlugin to the list of EventSubscriber in your ConsoleDependencyProvider.
- 4.18.0
- 4.17.1
- 4.17.0
- 4.16.0
- 4.15.0
- 4.14.0
- 4.13.0
- 4.12.0
- 4.11.0
- 4.10.4
- 4.10.3
- 4.10.2
- 4.10.1
- 4.10.0
- 4.9.0
- 4.8.0
- 4.7.0
- 4.6.0
- 4.5.1
- 4.5.0
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.0
- dev-master / 4.0.x-dev
- 4.0.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-RC2
- 2.0.0-RC1
- 1.0.0
- 0.20.0
- dev-beta/ai-foundation-rc1
- dev-hotfix/testing-propel
- dev-beta/glue-backend-prototype-v4
- dev-beta/spryker-mini-api-framework
- dev-beta/te-9873-backend-glue-application-plagin-context
- dev-beta/mp-5445-merchant-products-are-no-buyable
This package is auto-updated.
Last update: 2025-12-04 15:02:22 UTC
README
Console is a wrapper over Symfony's Console component, that makes the implementation and configuration of a console command easier. A console command is a php class that contains the implementation of a functionality that can get executed from the command line.
Installation
composer require spryker/console
Documentation
Testing Console Commands
The Console module provides a ConsoleHelper to simplify testing console commands using Codeception.
Using ConsoleHelper
The ConsoleHelper wraps your console command in a CommandTester instance, which allows you to execute the command programmatically and inspect its output and exit code.
Basic Usage
use Codeception\Test\Unit; use Symfony\Component\Console\Tester\CommandTester; use Spryker\Zed\YourModule\Communication\Plugin\Console\YourConsoleCommand; class YourConsoleCommandTest extends Unit { protected YourModuleTester $tester; public function testExecutesSuccessfully(): void { // Arrange $command = new YourConsoleCommand(); $commandTester = $this->tester->getConsoleTester($command); // Act $commandTester->execute([]); // Assert $this->assertSame(YourConsoleCommand::CODE_SUCCESS, $commandTester->getStatusCode()); $this->assertStringContainsString('Expected output', $commandTester->getDisplay()); } }
Passing Arguments and Options
The execute() method accepts an array of input parameters where:
- Arguments are passed by name:
['argumentName' => 'value'] - Options are passed with the
--prefix:['--option-name' => 'value']
public function testExecutesWithArguments(): void { // Arrange $command = new YourConsoleCommand(); $commandTester = $this->tester->getConsoleTester($command); // Act $commandTester->execute([ 'entityId' => 123, '--format' => 'json', '--verbose' => true, ]); // Assert $this->assertSame(YourConsoleCommand::CODE_SUCCESS, $commandTester->getStatusCode()); }
Execution Options
The execute() method accepts a second parameter for execution options:
$commandTester->execute( ['--option' => 'value'], [ 'interactive' => false, 'decorated' => false, 'verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'capture_stderr_separately' => true, ] );
Available execution options:
interactive: Sets the input interactive flagdecorated: Sets the output decorated flagverbosity: Sets the output verbosity levelcapture_stderr_separately: Make output of standard output and standard error separately available
Inspecting Command Output
After execution, you can inspect the command results:
$commandTester->execute([]); $exitCode = $commandTester->getStatusCode(); $output = $commandTester->getDisplay(); $input = $commandTester->getInput();
Testing Exception Cases
public function testThrowsExceptionWhenFileNotFound(): void { // Expect $this->expectException(FileNotFoundException::class); // Act $command = new YourConsoleCommand(); $commandTester = $this->tester->getConsoleTester($command); $commandTester->execute([ '--file' => 'invalid-file-path', ]); }
Helper Configuration
Ensure the ConsoleHelper is configured in your codeception.yml:
modules: enabled: - \SprykerTest\Shared\Console\Helper\ConsoleHelper