]> BookStack Code Mirror - system-cli/blob - tests/CommandResult.php
b8ee3b01d2a85db87dce862a46106a8936b170f4
[system-cli] / tests / CommandResult.php
1 <?php
2
3 namespace Tests;
4
5 use PHPUnit\Framework\Assert;
6 use Symfony\Component\Console\Tester\CommandTester;
7
8 class CommandResult
9 {
10
11     public function __construct(
12         protected CommandTester $tester,
13         protected ?\Exception $error
14     ) { }
15
16     public function assertSuccessfulExit(): void
17     {
18         Assert::assertEquals(0, $this->tester->getStatusCode());
19     }
20
21     public function assertErrorExit(): void
22     {
23         Assert::assertTrue($this->error !== null);
24     }
25
26     public function assertStdoutContains(string $needle): void
27     {
28         Assert::assertStringContainsString($needle, $this->tester->getDisplay());
29     }
30
31     public function assertStderrContains(string $needle): void
32     {
33         Assert::assertStringContainsString($needle, $this->error->getMessage() ?? '');
34     }
35
36
37 }