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