A bundle of methods that makes testing commands and shell classes easier.
Enables you to call commands/shells with a full application context.
array|nullThe customized application constructor arguments.
string|nullThe customized application class name.
Cake\Console\TestSuite\StubConsoleOutputConsole error output stub
int|nullLast exit code
Cake\Console\TestSuite\StubConsoleInputConsole input mock
Cake\Console\TestSuite\StubConsoleOutputConsole output stub
boolWhether to use the CommandRunner
Asserts stderr contains expected output
Asserts that stderr is empty
Asserts stderr contains expected regexp
Asserts shell exited with the expected code
Asserts shell exited with Command::CODE_ERROR
Asserts shell exited with the Command::CODE_SUCCESS
Asserts stdout contains expected output
Check that a row of cells exists in the output.
Asserts that stdout is empty
Asserts stdout does not contain expected output
Asserts stdout contains expected regexp
Cleans state to get ready for the next test
Clears any mocks that were defined and cleans up application class configuration.
Creates an $argv array from a command string
Configure the application class to use in integration tests.
Create an application instance.
Runs CLI integration test
Builds the appropriate command dispatcher
Add a mocked service to the container.
Wrap the application's container with one containing mocks.
Remove a mocked service to the container.
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
assertErrorContains(string $expected, string $message = ''): void
Asserts stderr contains expected output
string $expected Expected output
string $message optional Failure message
voidassertErrorEmpty(string $message = ''): void
Asserts that stderr is empty
string $message optional The message to output when the assertion fails.
voidassertErrorRegExp(string $pattern, string $message = ''): void
Asserts stderr contains expected regexp
string $pattern Expected pattern
string $message optional Failure message
voidassertExitCode(int $expected, string $message = ''): void
Asserts shell exited with the expected code
int $expected Expected exit code
string $message optional Failure message
voidassertExitError(string $message = ''): void
Asserts shell exited with Command::CODE_ERROR
string $message optional Failure message
voidassertExitSuccess(string $message = ''): void
Asserts shell exited with the Command::CODE_SUCCESS
string $message optional Failure message
voidassertOutputContains(string $expected, string $message = ''): void
Asserts stdout contains expected output
string $expected Expected output
string $message optional Failure message
voidassertOutputContainsRow(array $row, string $message = ''): void
Check that a row of cells exists in the output.
array $row Row of cells to ensure exist in the output.
string $message optional Failure message.
voidassertOutputEmpty(string $message = ''): void
Asserts that stdout is empty
string $message optional The message to output when the assertion fails.
voidassertOutputNotContains(string $expected, string $message = ''): void
Asserts stdout does not contain expected output
string $expected Expected output
string $message optional Failure message
voidassertOutputRegExp(string $pattern, string $message = ''): void
Asserts stdout contains expected regexp
string $pattern Expected pattern
string $message optional Failure message
voidcleanupConsoleTrait(): void
Cleans state to get ready for the next test
voidcleanupContainer(): void
Clears any mocks that were defined and cleans up application class configuration.
voidcommandStringToArgs(string $command): array<string>
Creates an $argv array from a command string
string $command Command string
array<string>configApplication(string $class, array|null $constructorArgs): void
Configure the application class to use in integration tests.
string $class The application class name.
array|null $constructorArgs The constructor arguments for your application class.
voidcreateApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
Create an application instance.
Uses the configuration set in configApplication().
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterfaceexec(string $command, array $input = []): void
Runs CLI integration test
string $command Command to run
array $input optional Input values to pass to an interactive shell
voidCake\Console\TestSuite\MissingConsoleInputExceptionRuntimeExceptionmakeRunner(): Cake\Console\CommandRunnerCake\Console\TestSuite\LegacyCommandRunner
Builds the appropriate command dispatcher
Cake\Console\CommandRunnerCake\Console\TestSuite\LegacyCommandRunnermockService(string $class, Closure $factory): $this
Add a mocked service to the container.
When the container is created the provided classname will be mapped to the factory function. The factory function will be used to create mocked services.
string $class The class or interface you want to define.
Closure $factory The factory function for mocked services.
$thismodifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): Cake\Core\ContainerInterface|null
Wrap the application's container with one containing mocks.
If any mocked services are defined, the application's container will be replaced with one containing mocks. The original container will be set as a delegate to the mock container.
Cake\Event\EventInterface $event The event
Cake\Core\ContainerInterface $container The container to wrap.
Cake\Core\ContainerInterface|nullremoveMockService(string $class): $this
Remove a mocked service to the container.
string $class The class or interface you want to remove.
$thisuseCommandRunner(): void
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
voidThe customized application constructor arguments.
array|nullThe customized application class name.
string|nullConsole error output stub
Cake\Console\TestSuite\StubConsoleOutputLast exit code
int|nullConsole input mock
Cake\Console\TestSuite\StubConsoleInputConsole output stub
Cake\Console\TestSuite\StubConsoleOutputWhether to use the CommandRunner
bool
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/trait-Cake.Console.TestSuite.ConsoleIntegrationTestTrait.html