]> BookStack Code Mirror - system-cli/blob - tests/CommandResult.php
Added testing for the update command
[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 getStderr(): string
17     {
18         return $this->error?->getMessage() ?? '';
19     }
20
21     public function assertSuccessfulExit(): void
22     {
23         Assert::assertEquals(0, $this->tester->getStatusCode());
24     }
25
26     public function assertErrorExit(): void
27     {
28         Assert::assertTrue($this->error !== null);
29     }
30
31     public function assertStdoutContains(string $needle): void
32     {
33         Assert::assertStringContainsString($needle, $this->tester->getDisplay());
34     }
35
36     public function assertStderrContains(string $needle): void
37     {
38         Assert::assertStringContainsString($needle, $this->getStderr());
39     }
40
41
42 }