ConsoleIntegrationTestTrait
A bundle of methods that makes testing commands and shell classes easier.
Enables you to call commands/shells with a full application context.
Table of Contents
Properties
- $_err : StubConsoleOutput
- Console error output stub
- $_exitCode : int|null
- Last exit code
- $_in : StubConsoleInput
- Console input mock
- $_out : StubConsoleOutput
- Console output stub
- $_useCommandRunner : bool
- Whether to use the CommandRunner
Methods
- assertErrorContains() : void
- Asserts `stderr` contains expected output
- assertErrorEmpty() : void
- Asserts that `stderr` is empty
- assertErrorRegExp() : void
- Asserts `stderr` contains expected regexp
- assertExitCode() : void
- Asserts shell exited with the expected code
- assertExitError() : void
- Asserts shell exited with Command::CODE_ERROR
- assertExitSuccess() : void
- Asserts shell exited with the Command::CODE_SUCCESS
- assertOutputContains() : void
- Asserts `stdout` contains expected output
- assertOutputEmpty() : void
- Asserts that `stdout` is empty
- assertOutputNotContains() : void
- Asserts `stdout` does not contain expected output
- assertOutputRegExp() : void
- Asserts `stdout` contains expected regexp
- cleanupConsoleTrait() : void
- Cleans state to get ready for the next test
- exec() : void
- Runs CLI integration test
- useCommandRunner() : void
- Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
- assertOutputContainsRow() : void
- Check that a row of cells exists in the output.
- commandStringToArgs() : array<string|int, string>
- Creates an $argv array from a command string
- makeRunner() : CommandRunner|LegacyCommandRunner
- Builds the appropriate command dispatcher
Properties
$_err
Console error output stub
protected
StubConsoleOutput
$_err
$_exitCode
Last exit code
protected
int|null
$_exitCode
$_in
Console input mock
protected
StubConsoleInput
$_in
$_out
Console output stub
protected
StubConsoleOutput
$_out
$_useCommandRunner
Whether to use the CommandRunner
protected
bool
$_useCommandRunner
= false
Methods
assertErrorContains()
Asserts `stderr` contains expected output
public
assertErrorContains(string $expected[, string $message = '' ]) : void
Parameters
- $expected : string
-
Expected output
- $message : string = ''
-
Failure message
assertErrorEmpty()
Asserts that `stderr` is empty
public
assertErrorEmpty([string $message = '' ]) : void
Parameters
- $message : string = ''
-
The message to output when the assertion fails.
assertErrorRegExp()
Asserts `stderr` contains expected regexp
public
assertErrorRegExp(string $pattern[, string $message = '' ]) : void
Parameters
- $pattern : string
-
Expected pattern
- $message : string = ''
-
Failure message
assertExitCode()
Asserts shell exited with the expected code
public
assertExitCode(int $expected[, string $message = '' ]) : void
Parameters
- $expected : int
-
Expected exit code
- $message : string = ''
-
Failure message
assertExitError()
Asserts shell exited with Command::CODE_ERROR
public
assertExitError([string $message = '' ]) : void
Parameters
- $message : string = ''
-
Failure message
assertExitSuccess()
Asserts shell exited with the Command::CODE_SUCCESS
public
assertExitSuccess([string $message = '' ]) : void
Parameters
- $message : string = ''
-
Failure message
assertOutputContains()
Asserts `stdout` contains expected output
public
assertOutputContains(string $expected[, string $message = '' ]) : void
Parameters
- $expected : string
-
Expected output
- $message : string = ''
-
Failure message
assertOutputEmpty()
Asserts that `stdout` is empty
public
assertOutputEmpty([string $message = '' ]) : void
Parameters
- $message : string = ''
-
The message to output when the assertion fails.
assertOutputNotContains()
Asserts `stdout` does not contain expected output
public
assertOutputNotContains(string $expected[, string $message = '' ]) : void
Parameters
- $expected : string
-
Expected output
- $message : string = ''
-
Failure message
assertOutputRegExp()
Asserts `stdout` contains expected regexp
public
assertOutputRegExp(string $pattern[, string $message = '' ]) : void
Parameters
- $pattern : string
-
Expected pattern
- $message : string = ''
-
Failure message
cleanupConsoleTrait()
Cleans state to get ready for the next test
public
cleanupConsoleTrait() : void
Tags
exec()
Runs CLI integration test
public
exec(string $command[, array<string|int, mixed> $input = [] ]) : void
Parameters
- $command : string
-
Command to run
- $input : array<string|int, mixed> = []
-
Input values to pass to an interactive shell
Tags
useCommandRunner()
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
public
useCommandRunner() : void
assertOutputContainsRow()
Check that a row of cells exists in the output.
protected
assertOutputContainsRow(array<string|int, mixed> $row[, string $message = '' ]) : void
Parameters
- $row : array<string|int, mixed>
-
Row of cells to ensure exist in the output.
- $message : string = ''
-
Failure message.
commandStringToArgs()
Creates an $argv array from a command string
protected
commandStringToArgs(string $command) : array<string|int, string>
Parameters
- $command : string
-
Command string
Return values
array<string|int, string>makeRunner()
Builds the appropriate command dispatcher
protected
makeRunner() : CommandRunner|LegacyCommandRunner