|
2 | 2 |
|
3 | 3 | namespace ErrorHeroModule\Spec\Integration; |
4 | 4 |
|
| 5 | +use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand; |
5 | 6 | use ErrorHeroModule\Controller\ErrorPreviewConsoleController; |
6 | 7 | use Kahlan\Plugin\Quit; |
7 | 8 | use Kahlan\QuitException; |
|
11 | 12 | use Laminas\Db\ResultSet\ResultSet; |
12 | 13 | use Laminas\Db\TableGateway\TableGateway; |
13 | 14 | use Laminas\Mvc\Application; |
| 15 | +use Symfony\Component\Console\Tester\CommandTester; |
| 16 | +use Webmozart\Assert\Assert; |
14 | 17 |
|
15 | 18 | describe('Integration via ErrorPreviewConsoleController', function (): void { |
16 | 19 |
|
17 | 20 | given('application', function () { |
18 | | - |
19 | | - Console::overrideIsConsole(true); |
20 | | - |
21 | 21 | $application = Application::init([ |
22 | 22 | 'modules' => [ |
23 | 23 | 'Laminas\Router', |
|
39 | 39 | $tableGateway->delete([]); |
40 | 40 |
|
41 | 41 | return $application; |
42 | | - |
43 | 42 | }); |
44 | 43 |
|
45 | 44 | describe('error-preview', function(): void { |
46 | 45 |
|
47 | 46 | it('show error page', function(): void { |
48 | 47 |
|
49 | | - Quit::disable(); |
| 48 | + /** @var ErrorPreviewConsoleCommand $command */ |
| 49 | + $command = $this->application->getServiceManager()->get(ErrorPreviewConsoleCommand::class); |
50 | 50 |
|
51 | | - $_SERVER['argv'] = [ |
52 | | - __FILE__, |
53 | | - 'error-preview', |
54 | | - 'controller' => ErrorPreviewConsoleController::class, |
55 | | - 'action' => 'exception', |
56 | | - ]; |
| 51 | + $commandTester = new CommandTester($command); |
| 52 | + $commandTester->execute([]); |
57 | 53 |
|
58 | | - \ob_start(); |
59 | | - $closure = function (): void { |
60 | | - $this->application->run(); |
61 | | - }; |
62 | | - expect($closure)->toThrow(new QuitException('Exit statement occurred', -1)); |
63 | | - $content = \ob_get_clean(); |
64 | | - |
65 | | - expect($content)->toContain('|We have encountered a problem and we can not fulfill your request'); |
| 54 | + expect($commandTester->getDisplay())->toContain('| We have encountered a problem and we can not fulfill your request'); |
66 | 55 |
|
67 | 56 | }); |
68 | 57 |
|
|
72 | 61 |
|
73 | 62 | it('show error page', function(): void { |
74 | 63 |
|
75 | | - Quit::disable(); |
76 | | - |
77 | | - $_SERVER['argv'] = [ |
78 | | - __FILE__, |
79 | | - 'error-preview', |
80 | | - 'controller' => ErrorPreviewConsoleController::class, |
81 | | - 'action' => 'error', |
82 | | - ]; |
| 64 | + /** @var ErrorPreviewConsoleCommand $command */ |
| 65 | + $command = $this->application->getServiceManager()->get(ErrorPreviewConsoleCommand::class); |
83 | 66 |
|
84 | | - \ob_start(); |
85 | | - $closure = function (): void { |
86 | | - $this->application->run(); |
87 | | - }; |
88 | | - expect($closure)->toThrow(new QuitException('Exit statement occurred', -1)); |
89 | | - $content = \ob_get_clean(); |
| 67 | + $commandTester = new CommandTester($command); |
| 68 | + $commandTester->execute([ |
| 69 | + 'type' => 'error', |
| 70 | + ]); |
90 | 71 |
|
91 | | - expect($content)->toContain('|We have encountered a problem and we can not fulfill your request'); |
| 72 | + expect($commandTester->getDisplay())->toContain('| We have encountered a problem and we can not fulfill your request'); |
92 | 73 |
|
93 | 74 | }); |
94 | 75 | }); |
|
0 commit comments