Skip to content

Commit 093f8e1

Browse files
committed
Merge branch 'allow-more-fatal-errors'
2 parents 98d28ca + fcca9c2 commit 093f8e1

File tree

14 files changed

+480
-221
lines changed

14 files changed

+480
-221
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ Give it a try!
313313

314314
_**Web Access**_
315315

316-
| URl | Preview For |
317-
|---------------------------------------|--------------|
318-
| http://yourzfapp/error-preview | Exception |
319-
| http://yourzfapp/error-preview/error | Error |
320-
| http://yourzfapp/error-preview/notice | PHP E_NOTICE |
316+
| URl | Preview For |
317+
|---------------------------------------|-----------------|
318+
| http://yourzfapp/error-preview | Exception |
319+
| http://yourzfapp/error-preview/error | Error |
320+
| http://yourzfapp/error-preview/notice | PHP E_NOTICE |
321+
| http://yourzfapp/error-preview/fatal | PHP Fatal Error |
321322

322323
You will get the following page if display_errors config is 0:
323324

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require-dev": {
2929
"aura/di": "^3.4",
3030
"doctrine/doctrine-orm-module": "^1.1",
31-
"kahlan/kahlan": "^4.1.1",
31+
"kahlan/kahlan": "~4.1.1",
3232
"northwoods/container": "^3.0",
3333
"php-coveralls/php-coveralls": "^2.0",
3434
"php-di/php-di": "^6.0",

kahlan-config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
'driver' => new Xdebug(),
1616
'path' => $this->commandLine()->get('src'),
1717
'exclude' => [
18-
'src/HeroAutoload.php',
18+
'src/Controller/ErrorPreviewConsoleController.php',
19+
'src/Controller/ErrorPreviewController.php',
20+
'src/Middleware/Routed/Preview/ErrorPreviewAction.php',
1921
],
2022
'colors' => ! $this->commandLine()->get('no-colors')
2123
]);

spec/Controller/ErrorPreviewConsoleControllerSpec.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

spec/Controller/ErrorPreviewControllerSpec.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

spec/Listener/MvcSpec.php

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ErrorHeroModule\Spec\Listener;
44

5+
use Closure;
56
use ErrorException;
67
use ErrorHeroModule\Handler\Logging;
78
use ErrorHeroModule\Listener\Mvc;
@@ -249,20 +250,61 @@
249250

250251
});
251252

253+
describe('->phpFatalErrorHandler()', function () {
254+
255+
it('returns buffer on no error', function () {
256+
257+
allow('error_get_last')->toBeCalled()->andReturn(null);
258+
expect($this->listener->phpFatalErrorHandler('test'))->toBe('test');
259+
260+
});
261+
262+
it('returns buffer on error has "Uncaught" prefix', function () {
263+
264+
allow('error_get_last')->toBeCalled()->andReturn([
265+
'message' => 'Uncaught',
266+
'type' => 3,
267+
]);
268+
expect($this->listener->phpFatalErrorHandler('Uncaught'))->toBe('Uncaught');
269+
270+
});
271+
272+
it('returns message value on error not has "Uncaught" prefix and result is empty', function () {
273+
274+
allow('error_get_last')->toBeCalled()->andReturn([
275+
'message' => 'Fatal',
276+
]);
277+
278+
expect($this->listener->phpFatalErrorHandler('Fatal'))->toBe('Fatal');
279+
280+
});
281+
282+
});
283+
252284
describe('->execOnShutdown()', function () {
253285

254-
it('call error_get_last() and return nothing', function () {
286+
it('call error_get_last() and return nothing and no result', function () {
255287

256288
allow('error_get_last')->toBeCalled()->andReturn(null);
257289
expect($this->listener->execOnShutdown())->toBeNull();
258290

259291
});
260292

261-
it('call error_get_last() and return error', function () {
293+
it('call error_get_last() and return nothing on result with "Uncaught" prefix', function () {
262294

263295
allow('error_get_last')->toBeCalled()->andReturn([
264-
'type' => 8,
265-
'message' => 'Undefined variable: a',
296+
'message' => 'Uncaught',
297+
'type' => 3,
298+
]);
299+
expect($this->listener->execOnShutdown())->toBeNull();
300+
301+
});
302+
303+
it('call error_get_last() and property_exists() after null check passed', function () {
304+
305+
allow('error_get_last')->toBeCalled()->andReturn([
306+
'type' => 3,
307+
'message' => 'class@anonymous cannot implement stdClass - it is not an interface',
266308
'file' => '/var/www/zf/module/Application/Module.php',
267309
'line' => 2
268310
]);
@@ -368,12 +410,16 @@
368410
$logging,
369411
$this->renderer
370412
);
413+
allow('property_exists')->toBeCalled()->with($listener, 'request')->andReturn(false);
414+
allow('property_exists')->toBeCalled()->with($listener, 'mvcEvent')->andReturn(true);
371415

372-
$closure = function () use ($listener) {
373-
$listener->execOnShutdown();
374-
};
375-
expect($closure)->toThrow(new ErrorException('Undefined variable: a', 0, 1, '/var/www/zf/module/Application/Module.php', 2));
416+
$mvcEvent = & Closure::bind(function & ($listener) {
417+
return $listener->mvcEvent;
418+
}, null, $listener)($listener);
419+
$mvcEvent = Double::instance(['extends' => MvcEvent::class, 'methods' => '__construct']);
420+
allow($mvcEvent)->toReceive('getRequest')->andReturn(new Request());
376421

422+
expect($listener->execOnShutdown())->toBeNull();
377423

378424
});
379425

@@ -402,6 +448,15 @@
402448

403449
});
404450

451+
it('throws ErrorException on non excluded php errors', function () {
452+
453+
$closure = function () {
454+
$this->listener->phpErrorHandler(\E_WARNING, 'warning', 'file.php', 1);
455+
};
456+
expect($closure)->toThrow(new \ErrorException('warning', 0, \E_WARNING, 'file.php', 1));
457+
458+
});
459+
405460
});
406461

407462
});

0 commit comments

Comments
 (0)