Skip to content

Commit a056976

Browse files
committed
Fixes #5
1 parent beee247 commit a056976

10 files changed

+244
-18
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
],
1616
"require": {
1717
"php": "^5.6|^7.0",
18+
"seld/jsonlint": "^1.5",
1819
"zendframework/zend-console": "^2.5",
1920
"zendframework/zend-db": "^2.5",
2021
"zendframework/zend-hydrator": "^1.0|^2.0",
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
return [
4+
5+
'db' => [
6+
'username' => 'root',
7+
'password' => '',
8+
'driver' => 'Pdo',
9+
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1',
10+
'driver_options' => [
11+
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
12+
],
13+
],
14+
15+
'log' => [
16+
'ErrorHeroModuleLogger' => [
17+
'writers' => [
18+
19+
[
20+
'name' => 'db',
21+
'options' => [
22+
'db' => 'Zend\Db\Adapter\Adapter',
23+
'table' => 'log',
24+
'column' => [
25+
'timestamp' => 'date',
26+
'priority' => 'type',
27+
'message' => 'event',
28+
'extra' => [
29+
'url' => 'url',
30+
'file' => 'file',
31+
'line' => 'line',
32+
'error_type' => 'error_type',
33+
'trace' => 'trace',
34+
'request_data' => 'request_data',
35+
],
36+
],
37+
],
38+
],
39+
40+
],
41+
],
42+
],
43+
44+
'error-hero-module' => [
45+
'enable' => true,
46+
'display-settings' => [
47+
48+
// excluded php errors
49+
'exclude-php-errors' => [
50+
E_USER_DEPRECATED
51+
],
52+
53+
// show or not error
54+
'display_errors' => 0,
55+
56+
// if enable and display_errors = 0, the page will bring layout and view
57+
'template' => [
58+
'layout' => 'layout/layout',
59+
'view' => 'error-hero-module/error-default'
60+
],
61+
62+
// if enable and display_errors = 0, the console will bring message
63+
'console' => [
64+
'message' => '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.',
65+
],
66+
67+
'ajax' => [
68+
'message' => '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.',
69+
],
70+
71+
],
72+
'logging-settings' => [
73+
'same-error-log-time-range' => 86400,
74+
],
75+
'email-notification-settings' => [
76+
// set to true to activate email notification on log error
77+
'enable' => false,
78+
79+
// Zend\Mail\Message instance registered at service manager
80+
'mail-message' => 'YourMailMessageService',
81+
82+
// Zend\Mail\Transport\TransportInterface instance registered at service manager
83+
'mail-transport' => 'YourMailTransportService',
84+
85+
// email sender
86+
'email-from' => 'Sender Name <[email protected]>',
87+
88+
'email-to-send' => [
89+
90+
91+
],
92+
],
93+
],
94+
];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace ErrorHeroModule;
4+
5+
use Zend\Log;
6+
use Zend\ServiceManager\Factory\InvokableFactory;
7+
8+
return [
9+
10+
'controllers' => [
11+
'factories' => [
12+
Controller\ErrorPreviewController::class => InvokableFactory::class,
13+
],
14+
],
15+
16+
'router' => [
17+
'routes' => [
18+
'error-preview' => [
19+
'type' => 'Segment',
20+
'options' => [
21+
'route' => '/error-preview[/][:action]',
22+
'defaults' => [
23+
'controller' => Controller\ErrorPreviewController::class,
24+
'action' => 'exception',
25+
],
26+
],
27+
],
28+
],
29+
],
30+
31+
'service_manager' => [
32+
'abstract_factories' => [
33+
Log\LoggerAbstractServiceFactory::class,
34+
],
35+
'factories' => [
36+
Listener\Mvc::class => Listener\MvcFactory::class,
37+
Handler\Logging::class => Handler\LoggingFactory::class,
38+
],
39+
],
40+
41+
'view_manager' => [
42+
'template_path_stack' => [
43+
__DIR__.'/../view',
44+
],
45+
],
46+
47+
];

spec/IntegrationViaErrorPreviewControllerForIdempotentSpec.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
$closure = function () {
5454
$this->application->run();
5555
};
56-
expect($closure)->toThrow(new QuitException());
56+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
5757
$content = ob_get_clean();
5858

5959
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
@@ -74,7 +74,7 @@
7474
$closure = function () {
7575
$this->application->run();
7676
};
77-
expect($closure)->toThrow(new QuitException());
77+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
7878
$content = ob_get_clean();
7979

8080
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
@@ -117,7 +117,7 @@
117117
$closure = function () use ($application) {
118118
$application->run();
119119
};
120-
expect($closure)->toThrow(new QuitException());
120+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
121121
$content = ob_get_clean();
122122

123123
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
@@ -142,7 +142,7 @@
142142
$closure = function () {
143143
$this->application->run();
144144
};
145-
expect($closure)->toThrow(new QuitException());
145+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
146146
$content = ob_get_clean();
147147

148148
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
@@ -163,7 +163,7 @@
163163
$closure = function () {
164164
$this->application->run();
165165
};
166-
expect($closure)->toThrow(new QuitException());
166+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
167167
$content = ob_get_clean();
168168

169169
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');

spec/IntegrationViaErrorPreviewControllerForXmlHttpRequestSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
$closure = function () {
5656
$this->application->run();
5757
};
58-
expect($closure)->toThrow(new QuitException());
58+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
5959
$content = ob_get_clean();
6060

6161
expect($content)->toBe(<<<json
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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-with-non-json-message/{{,*.}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('Exit statement occurred', -1));
59+
$content = ob_get_clean();
60+
61+
expect($content)->toBe('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.');
62+
63+
});
64+
65+
});
66+
67+
});

spec/IntegrationViaErrorPreviewControllerSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
$closure = function () {
6161
$this->application->run();
6262
};
63-
expect($closure)->toThrow(new QuitException());
63+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
6464
$content = ob_get_clean();
6565

6666
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
@@ -101,7 +101,7 @@
101101
$closure = function () use ($application) {
102102
$application->run();
103103
};
104-
expect($closure)->toThrow(new QuitException());
104+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
105105
$content = ob_get_clean();
106106

107107
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
@@ -126,7 +126,7 @@
126126
$closure = function () {
127127
$this->application->run();
128128
};
129-
expect($closure)->toThrow(new QuitException());
129+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
130130
$content = ob_get_clean();
131131

132132
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');

spec/IntegrationViaErrorPreviewControllerWithEnableSendMailSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
$closure = function () {
6161
$this->application->run();
6262
};
63-
expect($closure)->toThrow(new QuitException());
63+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
6464
$content = ob_get_clean();
6565

6666
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
@@ -101,7 +101,7 @@
101101
$closure = function () use ($application) {
102102
$application->run();
103103
};
104-
expect($closure)->toThrow(new QuitException());
104+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
105105
$content = ob_get_clean();
106106

107107
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
@@ -126,7 +126,7 @@
126126
$closure = function () {
127127
$this->application->run();
128128
};
129-
expect($closure)->toThrow(new QuitException());
129+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
130130
$content = ob_get_clean();
131131

132132
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');

spec/Listener/MvcSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
$closure = function () use ($listener, $mvcEvent) {
241241
$listener->exceptionError($mvcEvent);
242242
};
243-
expect($closure)->toThrow(new QuitException());
243+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
244244
$content = ob_get_clean();
245245

246246
expect($content)->toContain('We have encountered a problem');
@@ -261,7 +261,7 @@
261261
$closure = function () use ($mvcEvent) {
262262
$this->listener->exceptionError($mvcEvent);
263263
};
264-
expect($closure)->toThrow(new QuitException());
264+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
265265
$content = ob_get_clean();
266266

267267
expect($content)->toContain('We have encountered a problem');

0 commit comments

Comments
 (0)