Skip to content

Commit 33a0806

Browse files
committed
Fixes display_errors = 1 usage
1 parent de9d188 commit 33a0806

7 files changed

Lines changed: 59 additions & 19 deletions

File tree

spec/Integration/IntegrationViaErrorPreviewControllerForErrorShownSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
expect($content)->toBe('');
5555
} catch (\Throwable $t) {
56-
56+
expect($t)->toBeAnInstanceOf(\Exception::class);
5757
}
5858
});
5959
});

spec/Listener/MvcSpec.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@
283283

284284
it('call error_get_last() and return error', function () {
285285

286+
Quit::disable();
287+
286288
allow('error_get_last')->toBeCalled()->andReturn([
287289
'type' => 8,
288290
'message' => 'Undefined variable: a',
@@ -348,6 +350,15 @@
348350

349351
];
350352

353+
$resolver = new Resolver\AggregateResolver();
354+
355+
$map = new Resolver\TemplateMapResolver([
356+
'layout/layout' => __DIR__ . '/../Fixture/view/layout/layout.phtml',
357+
'error-hero-module/error-default' => __DIR__ . '/../Fixture/view/error-hero-module/error-default.phtml',
358+
]);
359+
$resolver->attach($map);
360+
$this->renderer->setResolver($resolver);
361+
351362
$logging = new Logging(
352363
$logger,
353364
'http://serverUrl',
@@ -395,11 +406,31 @@
395406
$logging,
396407
$this->renderer
397408
);
398-
$listener->execOnShutdown();
409+
410+
ob_start();
411+
$closure = function () use ($listener) {
412+
$listener->execOnShutdown();
413+
};
414+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
415+
$content = ob_get_clean();
416+
417+
expect($content)->toContain('We have encountered a problem');
399418

400419
});
401420

402421

403422
});
404423

424+
describe('->phpErrorHandler()', function () {
425+
426+
it('exclude error type and match', function () {
427+
428+
$this->listener->phpErrorHandler(E_USER_DEPRECATED, 'deprecated', 'file.php', 1);
429+
expect(error_reporting())->toBe(E_ALL | E_STRICT);
430+
expect(ini_get('display_errors'))->toBe("0");
431+
432+
});
433+
434+
});
435+
405436
});

spec/Middleware/ExpressiveSpec.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@
114114

115115
});
116116

117+
describe('->phpErrorHandler()', function () {
118+
119+
it('exclude error type and match', function () {
120+
121+
$this->middleware->phpErrorHandler(E_USER_DEPRECATED, 'deprecated', 'file.php', 1);
122+
expect(error_reporting())->toBe(E_ALL | E_STRICT);
123+
expect(ini_get('display_errors'))->toBe("0");
124+
125+
});
126+
127+
});
128+
117129
});

src/Controller/ErrorPreviewController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ public function errorAction()
1515
{
1616
$array = [];
1717
$array[1]; // E_NOTICE
18-
19-
return $this->getResponse();
2018
}
2119
}

src/Listener/Mvc.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function attach(EventManagerInterface $events, $priority = 1)
6363
*/
6464
public function phpError(Event $e)
6565
{
66+
if ($this->errorHeroModuleConfig['display-settings']['display_errors']) {
67+
return;
68+
}
69+
6670
register_shutdown_function([$this, 'execOnShutdown']);
6771
set_error_handler([$this, 'phpErrorHandler']);
6872
}
@@ -83,6 +87,11 @@ public function exceptionError(Event $e)
8387
$exception
8488
);
8589

90+
$displayErrors = $this->errorHeroModuleConfig['display-settings']['display_errors'];
91+
if ($displayErrors) {
92+
return;
93+
}
94+
8695
$this->showDefaultViewWhenDisplayErrorSetttingIsDisabled();
8796
}
8897

@@ -94,11 +103,6 @@ public function exceptionError(Event $e)
94103
*/
95104
private function showDefaultViewWhenDisplayErrorSetttingIsDisabled()
96105
{
97-
$displayErrors = $this->errorHeroModuleConfig['display-settings']['display_errors'];
98-
if ($displayErrors) {
99-
return;
100-
}
101-
102106
if (!Console::isConsole()) {
103107

104108
$response = new HttpResponse();

src/Middleware/Expressive.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
5454

5555
$this->phpError();
5656

57-
$response = $next($request, $response);
58-
59-
return $response;
57+
return $next($request, $response);
6058
} catch (Error $e) {
6159
$this->exceptionError($e, $request);
6260
} catch (Exception $e) {
@@ -70,6 +68,10 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
7068
*/
7169
public function phpError()
7270
{
71+
if ($this->errorHeroModuleConfig['display-settings']['display_errors']) {
72+
return;
73+
}
74+
7375
register_shutdown_function([$this, 'execOnShutdown']);
7476
set_error_handler([$this, 'phpErrorHandler']);
7577
}
@@ -101,11 +103,6 @@ public function exceptionError($e, $request)
101103
*/
102104
private function showDefaultViewWhenDisplayErrorSetttingIsDisabled()
103105
{
104-
$displayErrors = $this->errorHeroModuleConfig['display-settings']['display_errors'];
105-
if ($displayErrors) {
106-
return;
107-
}
108-
109106
$response = new Response();
110107
$response = $response->withStatus(500);
111108

src/Middleware/Routed/Preview/ErrorPreviewAction.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
2121

2222
$array = [];
2323
$array[1]; // E_NOTICE
24-
25-
return $response;
2624
}
2725
}

0 commit comments

Comments
 (0)