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\TestSuite\Stub\ConsoleOutput; $output = new ConsoleOutput(); $io = new ConsoleIo($output);
int
2
string
PHP_EOL
int
1
int
0
array
background colors used in colored output.
array
text colors used in colored output.
array
Formatting options for colored output.
array
Buffered messages.
resource
File handle for output.
int
The current output type.
array
Styles that are available as tags in console output.
__construct(string $stream)
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 $matches)
Replace tags with color codes.
array
$matches An array of matches to replace.
string
_write(string $message)
Writes a message to the output stream.
string
$message Message to write.
int
The number of bytes returned from writing to output.
getOutputAs()
Get the output type on how formatting tags are treated.
int
getStyle(string $style)
Gets the current styles offered
string
$style The style to get.
array
The style or empty array.
messages()
Get the buffered output.
array
output()
Get the output as a string
string
setOutputAs(int $type)
Set the output type on how formatting tags are treated.
int
$type The output type to use. Should be one of the class constants.
InvalidArgumentException
setStyle(string $style, array $definition)
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..
styleText(string $text)
Apply styling to text.
string
$text Text with styling tags.
string
String with color codes added.
styles()
Gets all the style definitions.
array
write(mixed $message, int $newlines)
Write output to the buffer.
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
text colors used in colored output.
array
Formatting options for colored output.
array
Buffered messages.
array
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
© 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.1/class-Cake.TestSuite.Stub.ConsoleOutput.html