This document describes included functions in the PhpRepos\Cli\Output
library.
function write(string $string): void
Print the given string
directly in the stdout with the default font color.
Using function import:
use function PhpRepos\Cli\Output\write;
write('Hello World!');
Using namespace import:
use PhpRepos\Cli\Output;
Output\write('Hello World!');
output('Hello World!'); // Output => Hello World!
function assert_output(string $expected, string $actual): bool
Assert to see the expected
string has been printed using the output
function and resulted in the actual
output.
Using function import:
use function PhpRepos\Cli\Output\assert_output;
$output = shell_exec('command');
assert_output($expected, $output);
Using namespace import:
use PhpRepos\Cli\Output;
$output = shell_exec('command');
Output\assert_output($expected, $output);
function line(string $string): void
Print the given string
directly in the stdout with the default font color and adds a PHP_EOL
to the end of given string.
Using function import:
use function PhpRepos\Cli\Output\line;
line('Hello World!');
Using namespace import:
use PhpRepos\Cli\Output;
Output\line('Hello World!');
line('Hello World!'); // Output => Hello World! \n
function assert_line(string $expected, string $actual): bool
Assert to see the expected
string has been printed using the line
function and resulted in the actual
output.
Using function import:
use function PhpRepos\Cli\Output\assert_line;
$output = shell_exec('command');
assert_line($expected, $output);
Using namespace import:
use PhpRepos\Cli\Output;
$output = shell_exec('command');
Output\assert_line($expected, $output);
function success(string $string): void
Print the given string
directly in the stdout with green font color and adds a PHP_EOL
to the end of given string.
Using function import:
use function PhpRepos\Cli\Output\success;
success('Hello World!');
Using namespace import:
use PhpRepos\Cli\Output;
Write\success('Hello World!');
success('Hello World!'); // Output(With a green font color) => Hello World! \n
function assert_success(string $expected, string $actual): bool
Assert to see the expected
string has been printed using the success
function and resulted in the actual
output.
Using function import:
use function PhpRepos\Cli\Output\assert_success;
$output = shell_exec('command');
assert_success($expected, $output);
Using namespace import:
use PhpRepos\Cli\Output;
$output = shell_exec('command');
Output\assert_success($expected, $output);
function error(string $string): void
Print the given string
directly in the stdout with red font color and adds a PHP_EOL
to the end of given string.
Using function import:
use function PhpRepos\Cli\Output\error;
error('Hello World!');
Using namespace import:
use PhpRepos\Cli\Output;
Output\error('Hello World!');
error('Hello World!'); // Output(With a red font color) => Hello World! \n
function assert_error(string $expected, string $actual): bool
Assert to see the expected
string has been printed using the error
function and resulted in the actual
output.
Using function import:
use function PhpRepos\Cli\Output\assert_error;
$output = shell_exec('command');
assert_error($expected, $output);
Using namespace import:
use PhpRepos\Cli\Output;
$output = shell_exec('command');
Output\assert_error($expected, $output);
function capture(Closure $closure): bool
This function allows you to capture the output generated by a closure or a set of commands, typically for further processing or manipulation.
Using function import:
use function PhpRepos\Cli\Output\capture
$output = capture(function () {
echo 'Hello ';
echo PHP_EOL;
printf(" %s", 'World');
});
assert_true("Hello \n World" === $output); // Returns true