Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions documentation/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can write such a test like this:
```php
use Innmind\CLI\{
Commands,
Environment\InMemory,
Environment,
};
use PHPUnit\Framework\TestCase;

Expand All @@ -22,7 +22,7 @@ class GreetTest extends TestCase
public function testCommandGreetsTheUser()
{
$commands = Commands::of(new Greet);
$environment = $commands(InMemory::of(
$environment = $commands(Environment::inMemory(
[], // no chunks in STDIN
false, // non interactive mode
['cli.php', 'greet', 'Bob'], // to simulate `php cli.php greet Bob`
Expand All @@ -31,9 +31,22 @@ class GreetTest extends TestCase
))->unwrap();

// it asked to output "Hi Bob\n"
$this->assertSame(["Hi Bob\n"], $environment->outputs());
$this->assertSame(
["Hi Bob\n"],
$environment
->outputted()
->filter(static fn($chunk) => $chunk[1] === 'output')
->map(static fn($chunk) => $chunk[0]->toString())
->toList(),
);
// it didn't write anything to STDERR
$this->assertSame([], $environment->errors());
$this->assertSame(
[],
$environment
->outputted()
->filter(static fn($chunk) => $chunk[1] === 'error')
->toList(),
);
// it didn't specify any exit code, meaning it will default to 0
$this->assertFalse($environment->exitCode()->match(
static fn() => true,
Expand Down