|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ErrorHeroModule\Spec; |
| 4 | + |
| 5 | +use ErrorHeroModule; |
| 6 | +use Zend\Console\Console; |
| 7 | +use Zend\Db\Adapter\AdapterInterface; |
| 8 | +use Zend\Db\ResultSet\ResultSet; |
| 9 | +use Zend\Db\TableGateway\TableGateway; |
| 10 | +use Zend\Mvc\Application; |
| 11 | + |
| 12 | +describe('Integration via ErrorPreviewController', function () { |
| 13 | + |
| 14 | + given('application', function () { |
| 15 | + |
| 16 | + Console::overrideIsConsole(false); |
| 17 | + |
| 18 | + $application = Application::init([ |
| 19 | + 'modules' => [ |
| 20 | + 'Zend\Router', |
| 21 | + 'Zend\Db', |
| 22 | + 'ErrorHeroModule', |
| 23 | + ], |
| 24 | + 'module_listener_options' => [ |
| 25 | + 'config_glob_paths' => [ |
| 26 | + \realpath(__DIR__).'/../Fixture/config/autoload-for-specific-error-and-exception/error-hero-module.local.php', |
| 27 | + \realpath(__DIR__).'/../Fixture/config/module.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('empty as rely to original mvc process to handle', function() { |
| 44 | + |
| 45 | + $request = $this->application->getRequest(); |
| 46 | + $request->setMethod('GET'); |
| 47 | + $request->setUri('http://example.com/error-preview'); |
| 48 | + $request->setRequestUri('/error-preview'); |
| 49 | + |
| 50 | + \ob_start(); |
| 51 | + $this->application->run(); |
| 52 | + $content = \ob_get_clean(); |
| 53 | + |
| 54 | + expect(\ob_get_clean())->toBe(''); |
| 55 | + expect($this->application->getResponse()->getStatusCode())->toBe(500); |
| 56 | + |
| 57 | + }); |
| 58 | + |
| 59 | + }); |
| 60 | + |
| 61 | + describe('/error-preview/notice', function() { |
| 62 | + |
| 63 | + it('empty as rely to original mvc process to handle', function() { |
| 64 | + |
| 65 | + @mkdir(__DIR__ . '/../Fixture/view/error-hero-module/error-preview', 0755, true); |
| 66 | + file_put_contents(__DIR__ . '/../Fixture/view/error-hero-module/error-preview/notice.phtml', ''); |
| 67 | + |
| 68 | + $request = $this->application->getRequest(); |
| 69 | + $request->setMethod('GET'); |
| 70 | + $request->setUri('http://example.com/error-preview/notice'); |
| 71 | + $request->setRequestUri('/error-preview/notice'); |
| 72 | + |
| 73 | + \ob_start(); |
| 74 | + $this->application->run(); |
| 75 | + $content = \ob_get_clean(); |
| 76 | + |
| 77 | + expect(\ob_get_clean())->toBe(''); |
| 78 | + // yes, excluded E_* error means it ignored, means it passed, means it is 200 status code |
| 79 | + expect($this->application->getResponse()->getStatusCode())->toBe(200); |
| 80 | + |
| 81 | + unlink(__DIR__ . '/../Fixture/view/error-hero-module/error-preview/notice.phtml'); |
| 82 | + rmdir(__DIR__ . '/../Fixture/view/error-hero-module/error-preview'); |
| 83 | + rmdir(__DIR__ . '/../Fixture/view/error-hero-module'); |
| 84 | + |
| 85 | + }); |
| 86 | + |
| 87 | + }); |
| 88 | + |
| 89 | + describe('/error-preview/error', function() { |
| 90 | + |
| 91 | + it('empty as rely to original mvc process to handle', function() { |
| 92 | + |
| 93 | + $request = $this->application->getRequest(); |
| 94 | + $request->setMethod('GET'); |
| 95 | + $request->setUri('http://example.com/error-preview/error'); |
| 96 | + $request->setRequestUri('/error-preview/error'); |
| 97 | + |
| 98 | + \ob_start(); |
| 99 | + $this->application->run(); |
| 100 | + $content = \ob_get_clean(); |
| 101 | + |
| 102 | + expect(\ob_get_clean())->toBe(''); |
| 103 | + expect($this->application->getResponse()->getStatusCode())->toBe(500); |
| 104 | + |
| 105 | + |
| 106 | + }); |
| 107 | + |
| 108 | + }); |
| 109 | + |
| 110 | +}); |
0 commit comments