Skip to content

Commit 8606a0a

Browse files
committed
test doctrine console
1 parent 6d2264a commit 8606a0a

File tree

2 files changed

+19
-41
lines changed

2 files changed

+19
-41
lines changed

spec/Integration/IntegrationViaErrorPreviewConsoleCommandSpec.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
namespace ErrorHeroModule\Spec\Integration;
44

55
use ErrorHeroModule\Command\Preview\ErrorPreviewConsoleCommand;
6-
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
7-
use Kahlan\Plugin\Quit;
8-
use Kahlan\QuitException;
9-
use Laminas\Console\Console;
106
use Laminas\Console\Request;
117
use Laminas\Db\Adapter\AdapterInterface;
128
use Laminas\Db\ResultSet\ResultSet;
139
use Laminas\Db\TableGateway\TableGateway;
1410
use Laminas\Mvc\Application;
1511
use Symfony\Component\Console\Tester\CommandTester;
16-
use Webmozart\Assert\Assert;
1712

1813
describe('Integration via ErrorPreviewConsoleController', function (): void {
1914

2015
given('application', function () {
16+
2117
$application = Application::init([
2218
'modules' => [
2319
'Laminas\Router',
@@ -39,6 +35,7 @@
3935
$tableGateway->delete([]);
4036

4137
return $application;
38+
4239
});
4340

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

spec/Integration/IntegrationViaErrorPreviewConsoleControllerWithDoctrineORMModuleSpec.php renamed to spec/Integration/IntegrationViaErrorPreviewConsoleCommandWithDoctrineORMModuleSpec.php

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
namespace ErrorHeroModule\Spec\Integration;
44

55
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;
107
use Laminas\Console\Request;
8+
use Laminas\Db\Adapter\AdapterInterface;
9+
use Laminas\Db\ResultSet\ResultSet;
10+
use Laminas\Db\TableGateway\TableGateway;
1111
use Laminas\Mvc\Application;
12+
use Symfony\Component\Console\Tester\CommandTester;
1213

1314
describe('Integration via ErrorPreviewConsoleController with doctrine', function (): void {
1415

1516
given('application', function () {
1617

17-
Console::overrideIsConsole(true);
18-
1918
$application = Application::init([
2019
'modules' => [
2120
'Laminas\Router',
@@ -45,23 +44,13 @@
4544

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

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

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([]);
6352

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

6655
});
6756

@@ -71,23 +60,15 @@
7160

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

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

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

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

9273
});
9374
});

0 commit comments

Comments
 (0)