Skip to content

Commit 6d2264a

Browse files
committed
use CommandTester
1 parent 4d391f2 commit 6d2264a

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

spec/Integration/IntegrationViaErrorPreviewConsoleControllerSpec.php renamed to spec/Integration/IntegrationViaErrorPreviewConsoleCommandSpec.php

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ErrorHeroModule\Spec\Integration;
44

5+
use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand;
56
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
67
use Kahlan\Plugin\Quit;
78
use Kahlan\QuitException;
@@ -11,13 +12,12 @@
1112
use Laminas\Db\ResultSet\ResultSet;
1213
use Laminas\Db\TableGateway\TableGateway;
1314
use Laminas\Mvc\Application;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
use Webmozart\Assert\Assert;
1417

1518
describe('Integration via ErrorPreviewConsoleController', function (): void {
1619

1720
given('application', function () {
18-
19-
Console::overrideIsConsole(true);
20-
2121
$application = Application::init([
2222
'modules' => [
2323
'Laminas\Router',
@@ -39,30 +39,19 @@
3939
$tableGateway->delete([]);
4040

4141
return $application;
42-
4342
});
4443

4544
describe('error-preview', function(): void {
4645

4746
it('show error page', function(): void {
4847

49-
Quit::disable();
48+
/** @var ErrorPreviewConsoleCommand $command */
49+
$command = $this->application->getServiceManager()->get(ErrorPreviewConsoleCommand::class);
5050

51-
$_SERVER['argv'] = [
52-
__FILE__,
53-
'error-preview',
54-
'controller' => ErrorPreviewConsoleController::class,
55-
'action' => 'exception',
56-
];
51+
$commandTester = new CommandTester($command);
52+
$commandTester->execute([]);
5753

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');
6655

6756
});
6857

@@ -72,23 +61,15 @@
7261

7362
it('show error page', function(): void {
7463

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);
8366

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+
]);
9071

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');
9273

9374
});
9475
});

0 commit comments

Comments
 (0)