|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ErrorHeroModule\Spec; |
| 4 | + |
| 5 | +use ErrorHeroModule; |
| 6 | +use ErrorHeroModule\Controller\ErrorPreviewConsoleController; |
| 7 | +use Kahlan\Plugin\Quit; |
| 8 | +use Kahlan\QuitException; |
| 9 | +use Zend\Console\Console; |
| 10 | +use Zend\Db\ResultSet\ResultSet; |
| 11 | +use Zend\Db\TableGateway\TableGateway; |
| 12 | +use Zend\Log; |
| 13 | +use Zend\Mvc\Application; |
| 14 | + |
| 15 | +describe('Integration via ErrorPreviewConsoleController', function () { |
| 16 | + |
| 17 | + given('application', function () { |
| 18 | + |
| 19 | + Console::overrideIsConsole(true); |
| 20 | + |
| 21 | + $application = Application::init([ |
| 22 | + 'modules' => [ |
| 23 | + 'Zend\Router', |
| 24 | + 'Zend\Db', |
| 25 | + 'ErrorHeroModule', |
| 26 | + ], |
| 27 | + 'module_listener_options' => [ |
| 28 | + 'config_glob_paths' => [ |
| 29 | + realpath(__DIR__).'/Fixture/autoload/{{,*.}global,{,*.}local}.php', |
| 30 | + ], |
| 31 | + ], |
| 32 | + ]); |
| 33 | + |
| 34 | + $events = $application->getEventManager(); |
| 35 | + $serviceManager = $application->getServiceManager(); |
| 36 | + $serviceManager->get('SendResponseListener') |
| 37 | + ->detach($events); |
| 38 | + |
| 39 | + $db = $serviceManager->get('Zend\Db\Adapter\Adapter'); |
| 40 | + $tableGateway = new TableGateway('log', $db, null, new ResultSet()); |
| 41 | + $tableGateway->delete([]); |
| 42 | + |
| 43 | + return $application; |
| 44 | + |
| 45 | + }); |
| 46 | + |
| 47 | + describe('/error-preview', function() { |
| 48 | + |
| 49 | + it('show error page', function() { |
| 50 | + |
| 51 | + skipIf(PHP_MAJOR_VERSION < 7); |
| 52 | + |
| 53 | + Quit::disable(); |
| 54 | + |
| 55 | + $_SERVER['argv'] = [ |
| 56 | + __FILE__, |
| 57 | + 'error-preview', |
| 58 | + 'controller' => ErrorPreviewConsoleController::class, |
| 59 | + 'action' => 'exception', |
| 60 | + ]; |
| 61 | + |
| 62 | + ob_start(); |
| 63 | + $closure = function () { |
| 64 | + $this->application->run(); |
| 65 | + }; |
| 66 | + expect($closure)->toThrow(new QuitException('Exit statement occurred', -1)); |
| 67 | + $content = ob_get_clean(); |
| 68 | + |
| 69 | + expect($content)->toContain('|We have encountered a problem and we can not fulfill your request'); |
| 70 | + |
| 71 | + }); |
| 72 | + |
| 73 | + }); |
| 74 | + |
| 75 | + describe('/error-preview/error', function() { |
| 76 | + |
| 77 | + it('show error page', function() { |
| 78 | + |
| 79 | + skipIf(PHP_MAJOR_VERSION < 7); |
| 80 | + |
| 81 | + Quit::disable(); |
| 82 | + |
| 83 | + $_SERVER['argv'] = [ |
| 84 | + __FILE__, |
| 85 | + 'error-preview', |
| 86 | + 'controller' => ErrorPreviewConsoleController::class, |
| 87 | + 'action' => 'error', |
| 88 | + ]; |
| 89 | + |
| 90 | + ob_start(); |
| 91 | + $closure = function () { |
| 92 | + $this->application->run(); |
| 93 | + }; |
| 94 | + expect($closure)->toThrow(new QuitException('Exit statement occurred', -1)); |
| 95 | + $content = ob_get_clean(); |
| 96 | + |
| 97 | + expect($content)->toContain('|We have encountered a problem and we can not fulfill your request'); |
| 98 | + |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | +}); |
0 commit comments