StubOutput makes testing shell commands/shell helpers easier.
You can use this class by injecting it into a ConsoleIo instance that your command/task/helper uses:
use Cake\Console\ConsoleIo; use Cake\Console\TestSuite\StubConsoleOutput; $output = new StubConsoleOutput(); $io = new ConsoleIo($output);
int
2
Color output - Convert known tags in to ANSI color escape codes.
string
PHP_EOL
Constant for a newline.
int
1
Plain output - tags will be stripped.
int
0
Raw output constant - no modification of output text.
array<string, int>
background colors used in colored output.
array<string, int>
text colors used in colored output.
array<string, int>
Formatting options for colored output.
array<string>
Buffered messages.
resource
File handle for output.
int
The current output type.
array<string, array>
Styles that are available as tags in console output. You can modify these styles with ConsoleOutput::styles()
Construct the output object.
Clean up and close handles
Replace tags with color codes.
Writes a message to the output stream.
Get the output type on how formatting tags are treated.
Gets the current styles offered
Get the buffered output.
Get the output as a string
Set the output type on how formatting tags are treated.
Sets style.
Apply styling to text.
Gets all the style definitions.
Write output to the buffer.
__construct(string $stream = 'php://stdout')
Construct the output object.
Checks for a pretty console environment. Ansicon and ConEmu allows pretty consoles on Windows, and is supported.
string
$stream optional The identifier of the stream to write output to.
__destruct()
Clean up and close handles
_replaceTags(array<string, string> $matches): string
Replace tags with color codes.
array<string, string>
$matches An array of matches to replace.
string
_write(string $message): int
Writes a message to the output stream.
string
$message Message to write.
int
getOutputAs(): int
Get the output type on how formatting tags are treated.
int
getStyle(string $style): array
Gets the current styles offered
string
$style The style to get.
array
messages(): array<string>
Get the buffered output.
array<string>
output(): string
Get the output as a string
string
setOutputAs(int $type): void
Set the output type on how formatting tags are treated.
int
$type The output type to use. Should be one of the class constants.
void
InvalidArgumentException
setStyle(string $style, array $definition): void
Sets style.
$output->setStyle('annoy', ['text' => 'purple', 'background' => 'yellow', 'blink' => true]);
$this->output->setStyle('annoy', []);
string
$style The style to set.
array
$definition The array definition of the style to change or create..
void
styleText(string $text): string
Apply styling to text.
string
$text Text with styling tags.
string
styles(): array<string, mixed>
Gets all the style definitions.
array<string, mixed>
write(array<string>|string $message, int $newlines = 1): int
Write output to the buffer.
array<string>|string
$message A string or an array of strings to output
int
$newlines optional Number of newlines to append
int
background colors used in colored output.
array<string, int>
text colors used in colored output.
array<string, int>
Formatting options for colored output.
array<string, int>
Buffered messages.
array<string>
File handle for output.
resource
The current output type.
int
Styles that are available as tags in console output. You can modify these styles with ConsoleOutput::styles()
array<string, array>
© 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/class-Cake.Console.TestSuite.StubConsoleOutput.html