A bundle of methods that makes testing commands and shell classes easier.
Enables you to call commands/shells with a full application context.
array|null
The customized application constructor arguments.
string|null
The customized application class name.
Cake\Console\TestSuite\StubConsoleOutput
Console error output stub
int|null
Last exit code
Cake\Console\TestSuite\StubConsoleInput
Console input mock
Cake\Console\TestSuite\StubConsoleOutput
Console output stub
bool
Whether 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
void
assertErrorEmpty(string $message = ''): void
Asserts that stderr
is empty
string
$message optional The message to output when the assertion fails.
void
assertErrorRegExp(string $pattern, string $message = ''): void
Asserts stderr
contains expected regexp
string
$pattern Expected pattern
string
$message optional Failure message
void
assertExitCode(int $expected, string $message = ''): void
Asserts shell exited with the expected code
int
$expected Expected exit code
string
$message optional Failure message
void
assertExitError(string $message = ''): void
Asserts shell exited with Command::CODE_ERROR
string
$message optional Failure message
void
assertExitSuccess(string $message = ''): void
Asserts shell exited with the Command::CODE_SUCCESS
string
$message optional Failure message
void
assertOutputContains(string $expected, string $message = ''): void
Asserts stdout
contains expected output
string
$expected Expected output
string
$message optional Failure message
void
assertOutputContainsRow(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.
void
assertOutputEmpty(string $message = ''): void
Asserts that stdout
is empty
string
$message optional The message to output when the assertion fails.
void
assertOutputNotContains(string $expected, string $message = ''): void
Asserts stdout
does not contain expected output
string
$expected Expected output
string
$message optional Failure message
void
assertOutputRegExp(string $pattern, string $message = ''): void
Asserts stdout
contains expected regexp
string
$pattern Expected pattern
string
$message optional Failure message
void
cleanupConsoleTrait(): void
Cleans state to get ready for the next test
void
cleanupContainer(): void
Clears any mocks that were defined and cleans up application class configuration.
void
commandStringToArgs(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.
void
createApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
Create an application instance.
Uses the configuration set in configApplication()
.
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
exec(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
void
Cake\Console\TestSuite\MissingConsoleInputException
RuntimeException
makeRunner(): Cake\Console\CommandRunnerCake\Console\TestSuite\LegacyCommandRunner
Builds the appropriate command dispatcher
Cake\Console\CommandRunnerCake\Console\TestSuite\LegacyCommandRunner
mockService(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.
$this
modifyContainer(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|null
removeMockService(string $class): $this
Remove a mocked service to the container.
string
$class The class or interface you want to remove.
$this
useCommandRunner(): void
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
void
The customized application constructor arguments.
array|null
The customized application class name.
string|null
Console error output stub
Cake\Console\TestSuite\StubConsoleOutput
Last exit code
int|null
Console input mock
Cake\Console\TestSuite\StubConsoleInput
Console output stub
Cake\Console\TestSuite\StubConsoleOutput
Whether 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