Trait ConsoleIntegrationTestTrait
A test case class intended to make integration tests of cake console commands easier.
Property Summary
-
$_appArgs protected
array|nullThe customized application constructor arguments.
-
$_appClass protected
string|nullThe customized application class name.
-
$_err protected
Cake\TestSuite\Stub\ConsoleOutputConsole error output stub
-
$_exitCode protected
int|nullLast exit code
-
$_in protected
Cake\Console\ConsoleInputConsole input mock
-
$_out protected
Cake\TestSuite\Stub\ConsoleOutputConsole output stub
-
$_useCommandRunner protected
boolWhether or not to use the CommandRunner
Method Summary
-
assertErrorContains() public
Asserts
stderrcontains expected output -
assertErrorEmpty() public
Asserts that
stderris empty -
assertErrorRegExp() public
Asserts
stderrcontains expected regexp -
assertExitCode() public
Asserts shell exited with the expected code
-
assertExitError() public
Asserts shell exited with Command::CODE_ERROR
-
assertExitSuccess() public
Asserts shell exited with the Command::CODE_SUCCESS
-
assertOutputContains() public
Asserts
stdoutcontains expected output -
assertOutputContainsRow() protected
Check that a row of cells exists in the output.
-
assertOutputEmpty() public
Asserts that
stdoutis empty -
assertOutputNotContains() public
Asserts
stdoutdoes not contain expected output -
assertOutputRegExp() public
Asserts
stdoutcontains expected regexp -
cleanupConsoleTrait() public
Cleans state to get ready for the next test
-
commandStringToArgs() protected
Creates an $argv array from a command string
-
configApplication() public
Configure the application class to use in console integration tests.
-
exec() public
Runs cli integration test
-
makeRunner() protected
Builds the appropriate command dispatcher
-
useCommandRunner() public
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
Method Detail
assertErrorContains() ¶ public
assertErrorContains(string $expected, string $message = ''): void
Asserts stderr contains expected output
Parameters
-
string$expected Expected output
-
string$message optional Failure message
Returns
voidassertErrorEmpty() ¶ public
assertErrorEmpty(string $message = ''): void
Asserts that stderr is empty
Parameters
-
string$message optional The message to output when the assertion fails.
Returns
voidassertErrorRegExp() ¶ public
assertErrorRegExp(string $pattern, string $message = ''): void
Asserts stderr contains expected regexp
Parameters
-
string$pattern Expected pattern
-
string$message optional Failure message
Returns
voidassertExitCode() ¶ public
assertExitCode(int $expected, string $message = ''): void
Asserts shell exited with the expected code
Parameters
-
int$expected Expected exit code
-
string$message optional Failure message
Returns
voidassertExitError() ¶ public
assertExitError(string $message = ''): void
Asserts shell exited with Command::CODE_ERROR
Parameters
-
string$message optional Failure message
Returns
voidassertExitSuccess() ¶ public
assertExitSuccess(string $message = ''): void
Asserts shell exited with the Command::CODE_SUCCESS
Parameters
-
string$message optional Failure message
Returns
voidassertOutputContains() ¶ public
assertOutputContains(string $expected, string $message = ''): void
Asserts stdout contains expected output
Parameters
-
string$expected Expected output
-
string$message optional Failure message
Returns
voidassertOutputContainsRow() ¶ protected
assertOutputContainsRow(array $row, string $message = ''): void
Check that a row of cells exists in the output.
Parameters
-
array$row Row of cells to ensure exist in the output.
-
string$message optional Failure message.
Returns
voidassertOutputEmpty() ¶ public
assertOutputEmpty(string $message = ''): void
Asserts that stdout is empty
Parameters
-
string$message optional The message to output when the assertion fails.
Returns
voidassertOutputNotContains() ¶ public
assertOutputNotContains(string $expected, string $message = ''): void
Asserts stdout does not contain expected output
Parameters
-
string$expected Expected output
-
string$message optional Failure message
Returns
voidassertOutputRegExp() ¶ public
assertOutputRegExp(string $pattern, string $message = ''): void
Asserts stdout contains expected regexp
Parameters
-
string$pattern Expected pattern
-
string$message optional Failure message
Returns
voidcleanupConsoleTrait() ¶ public
cleanupConsoleTrait(): void
Cleans state to get ready for the next test
Returns
voidcommandStringToArgs() ¶ protected
commandStringToArgs(string $command): string[]
Creates an $argv array from a command string
Parameters
-
string$command Command string
Returns
string[]configApplication() ¶ public
configApplication(string $class, array|null $constructorArgs): void
Configure the application class to use in console integration tests.
Parameters
-
string$class The application class name.
-
array|null$constructorArgs The constructor arguments for your application class.
Returns
voidexec() ¶ public
exec(string $command, array $input = []): void
Runs cli integration test
Parameters
-
string$command Command to run
-
array$input optional Input values to pass to an interactive shell
Returns
voidThrows
Cake\TestSuite\Stub\MissingConsoleInputExceptionRuntimeExceptionmakeRunner() ¶ protected
makeRunner(): Cake\Console\CommandRunner|Cake\TestSuite\LegacyCommandRunner
Builds the appropriate command dispatcher
Returns
Cake\Console\CommandRunner|Cake\TestSuite\LegacyCommandRunneruseCommandRunner() ¶ public
useCommandRunner(): void
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
Returns
void