Output Library

This document describes included functions in the PhpRepos\Cli\Output library.

output

function write(string $string): void

Description

Print the given string directly in the stdout with the default font color.

Usages

Using function import:

use function PhpRepos\Cli\Output\write;

write('Hello World!');

Using namespace import:

use PhpRepos\Cli\Output;

Output\write('Hello World!');

Examples

output('Hello World!'); // Output => Hello World! 

assert_output

function assert_output(string $expected, string $actual): bool

Description

Assert to see the expected string has been printed using the output function and resulted in the actual output.

Usages

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);

line

function line(string $string): void

Description

Print the given string directly in the stdout with the default font color and adds a PHP_EOL to the end of given string.

Usages

Using function import:

use function PhpRepos\Cli\Output\line;

line('Hello World!');

Using namespace import:

use PhpRepos\Cli\Output;

Output\line('Hello World!');

Examples

line('Hello World!'); // Output => Hello World! \n

assert_line

function assert_line(string $expected, string $actual): bool

Description

Assert to see the expected string has been printed using the line function and resulted in the actual output.

Usages

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);

success

function success(string $string): void

Description

Print the given string directly in the stdout with green font color and adds a PHP_EOL to the end of given string.

Usages

Using function import:

use function PhpRepos\Cli\Output\success;

success('Hello World!');

Using namespace import:

use PhpRepos\Cli\Output;

Write\success('Hello World!');

Examples

success('Hello World!'); // Output(With a green font color) => Hello World! \n

assert_success

function assert_success(string $expected, string $actual): bool

Description

Assert to see the expected string has been printed using the success function and resulted in the actual output.

Usages

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);

error

function error(string $string): void

Description

Print the given string directly in the stdout with red font color and adds a PHP_EOL to the end of given string.

Usages

Using function import:

use function PhpRepos\Cli\Output\error;

error('Hello World!');

Using namespace import:

use PhpRepos\Cli\Output;

Output\error('Hello World!');

Examples

error('Hello World!'); // Output(With a red font color) => Hello World! \n

assert_error

function assert_error(string $expected, string $actual): bool

Description

Assert to see the expected string has been printed using the error function and resulted in the actual output.

Usages

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);

capture

function capture(Closure $closure): bool

Description

This function allows you to capture the output generated by a closure or a set of commands, typically for further processing or manipulation.

Usages

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