|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ErrorHeroModule\Spec\Integration; |
| 4 | + |
| 5 | +use ErrorHeroModule; |
| 6 | +use ErrorHeroModule\Controller\ErrorPreviewController; |
| 7 | +use Kahlan\Plugin\Quit; |
| 8 | +use Kahlan\QuitException; |
| 9 | +use Zend\Console\Console; |
| 10 | +use Zend\Http\PhpEnvironment\Request; |
| 11 | +use Zend\Mvc\Application; |
| 12 | + |
| 13 | +describe('Integration via ErrorPreviewController for XmlHttpRequest', function () { |
| 14 | + |
| 15 | + given('application', function () { |
| 16 | + |
| 17 | + Console::overrideIsConsole(false); |
| 18 | + |
| 19 | + $application = Application::init([ |
| 20 | + 'modules' => [ |
| 21 | + 'Zend\Router', |
| 22 | + 'Zend\Db', |
| 23 | + 'ErrorHeroModule', |
| 24 | + ], |
| 25 | + 'module_listener_options' => [ |
| 26 | + 'config_glob_paths' => [ |
| 27 | + realpath(__DIR__).'/Fixture/autoload-for-xmlhttprequest/{{,*.}global,{,*.}local}.php', |
| 28 | + ], |
| 29 | + ], |
| 30 | + ]); |
| 31 | + |
| 32 | + $events = $application->getEventManager(); |
| 33 | + $serviceManager = $application->getServiceManager(); |
| 34 | + $serviceManager->get('SendResponseListener') |
| 35 | + ->detach($events); |
| 36 | + |
| 37 | + return $application; |
| 38 | + |
| 39 | + }); |
| 40 | + |
| 41 | + describe('/error-preview', function() { |
| 42 | + |
| 43 | + it('show error page', function() { |
| 44 | + |
| 45 | + skipIf(PHP_MAJOR_VERSION < 7); |
| 46 | + Quit::disable(); |
| 47 | + |
| 48 | + $request = $this->application->getRequest(); |
| 49 | + $request->setMethod('GET'); |
| 50 | + $request->setUri('/error-preview'); |
| 51 | + |
| 52 | + allow(Request::class)->toReceive('isXmlHttpRequest')->andReturn(true); |
| 53 | + |
| 54 | + ob_start(); |
| 55 | + $closure = function () { |
| 56 | + $this->application->run(); |
| 57 | + }; |
| 58 | + expect($closure)->toThrow(new QuitException()); |
| 59 | + $content = ob_get_clean(); |
| 60 | + |
| 61 | + expect($content)->toBe(<<<json |
| 62 | +{ |
| 63 | + "error": "We have encountered a problem and we can not fulfill your request. An error report has been generated and send to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience." |
| 64 | +} |
| 65 | +json |
| 66 | + ); |
| 67 | + |
| 68 | + }); |
| 69 | + |
| 70 | + }); |
| 71 | + |
| 72 | +}); |
0 commit comments