|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ErrorHeroModule\Spec; |
| 4 | + |
| 5 | +use ErrorHeroModule; |
| 6 | +use ErrorHeroModule\Controller\ErrorPreviewController; |
| 7 | +use Zend\Console\Console; |
| 8 | +use Zend\Db\Adapter\Adapter; |
| 9 | +use Zend\Db\ResultSet\ResultSet; |
| 10 | +use Zend\Db\TableGateway\TableGateway; |
| 11 | +use Zend\Http\Header\Cookie; |
| 12 | +use Zend\Mvc\Application; |
| 13 | + |
| 14 | +describe('Integration via ErrorPreviewController for has cookie', function () { |
| 15 | + |
| 16 | + given('application', function () { |
| 17 | + |
| 18 | + Console::overrideIsConsole(false); |
| 19 | + |
| 20 | + $application = Application::init([ |
| 21 | + 'modules' => [ |
| 22 | + 'Zend\Router', |
| 23 | + 'Zend\Db', |
| 24 | + 'ErrorHeroModule', |
| 25 | + ], |
| 26 | + 'module_listener_options' => [ |
| 27 | + 'config_glob_paths' => [ |
| 28 | + realpath(__DIR__).'/../Fixture/config/autoload/error-hero-module.local.php', |
| 29 | + realpath(__DIR__).'/../Fixture/config/module.local.php', |
| 30 | + ], |
| 31 | + ], |
| 32 | + ]); |
| 33 | + |
| 34 | + $events = $application->getEventManager(); |
| 35 | + $serviceManager = $application->getServiceManager(); |
| 36 | + |
| 37 | + $db = $serviceManager->get(Adapter::class); |
| 38 | + $tableGateway = new TableGateway('log', $db, null, new ResultSet()); |
| 39 | + $tableGateway->delete([]); |
| 40 | + |
| 41 | + $application->getRequest()->setCookies(['foo' => 'value']); |
| 42 | + |
| 43 | + return $application; |
| 44 | + |
| 45 | + }); |
| 46 | + |
| 47 | + describe('/error-preview', function() { |
| 48 | + |
| 49 | + it('show error page', function() { |
| 50 | + |
| 51 | + $request = $this->application->getRequest(); |
| 52 | + $request->setMethod('GET'); |
| 53 | + $request->setUri('http://example.com/error-preview'); |
| 54 | + $request->setRequestUri('/error-preview'); |
| 55 | + |
| 56 | + ob_start(); |
| 57 | + $this->application->run(); |
| 58 | + $content = ob_get_clean(); |
| 59 | + |
| 60 | + expect($content)->toContain('<title>Error'); |
| 61 | + expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request'); |
| 62 | + expect($this->application->getResponse()->getStatusCode())->toBe(500); |
| 63 | + |
| 64 | + }); |
| 65 | + |
| 66 | + }); |
| 67 | + |
| 68 | + describe('/error-preview/error', function() { |
| 69 | + |
| 70 | + it('show error page', function() { |
| 71 | + |
| 72 | + $request = $this->application->getRequest(); |
| 73 | + $request->setMethod('GET'); |
| 74 | + $request->setUri('http://example.com/error-preview/error'); |
| 75 | + $request->setRequestUri('/error-preview/error'); |
| 76 | + |
| 77 | + ob_start(); |
| 78 | + $this->application->run(); |
| 79 | + $content = ob_get_clean(); |
| 80 | + |
| 81 | + expect($content)->toContain('<title>Error'); |
| 82 | + expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request'); |
| 83 | + expect($this->application->getResponse()->getStatusCode())->toBe(500); |
| 84 | + |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | +}); |
0 commit comments