Skip to content

Commit

Permalink
Merge branch 'allow-more-fatal-errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 21, 2018
2 parents 98d28ca + fcca9c2 commit 093f8e1
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 221 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ Give it a try!

_**Web Access**_

| URl | Preview For |
|---------------------------------------|--------------|
| http://yourzfapp/error-preview | Exception |
| http://yourzfapp/error-preview/error | Error |
| http://yourzfapp/error-preview/notice | PHP E_NOTICE |
| URl | Preview For |
|---------------------------------------|-----------------|
| http://yourzfapp/error-preview | Exception |
| http://yourzfapp/error-preview/error | Error |
| http://yourzfapp/error-preview/notice | PHP E_NOTICE |
| http://yourzfapp/error-preview/fatal | PHP Fatal Error |

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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require-dev": {
"aura/di": "^3.4",
"doctrine/doctrine-orm-module": "^1.1",
"kahlan/kahlan": "^4.1.1",
"kahlan/kahlan": "~4.1.1",
"northwoods/container": "^3.0",
"php-coveralls/php-coveralls": "^2.0",
"php-di/php-di": "^6.0",
Expand Down
4 changes: 3 additions & 1 deletion kahlan-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'driver' => new Xdebug(),
'path' => $this->commandLine()->get('src'),
'exclude' => [
'src/HeroAutoload.php',
'src/Controller/ErrorPreviewConsoleController.php',
'src/Controller/ErrorPreviewController.php',
'src/Middleware/Routed/Preview/ErrorPreviewAction.php',
],
'colors' => ! $this->commandLine()->get('no-colors')
]);
Expand Down
59 changes: 0 additions & 59 deletions spec/Controller/ErrorPreviewConsoleControllerSpec.php

This file was deleted.

45 changes: 0 additions & 45 deletions spec/Controller/ErrorPreviewControllerSpec.php

This file was deleted.

71 changes: 63 additions & 8 deletions spec/Listener/MvcSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ErrorHeroModule\Spec\Listener;

use Closure;
use ErrorException;
use ErrorHeroModule\Handler\Logging;
use ErrorHeroModule\Listener\Mvc;
Expand Down Expand Up @@ -249,20 +250,61 @@

});

describe('->phpFatalErrorHandler()', function () {

it('returns buffer on no error', function () {

allow('error_get_last')->toBeCalled()->andReturn(null);
expect($this->listener->phpFatalErrorHandler('test'))->toBe('test');

});

it('returns buffer on error has "Uncaught" prefix', function () {

allow('error_get_last')->toBeCalled()->andReturn([
'message' => 'Uncaught',
'type' => 3,
]);
expect($this->listener->phpFatalErrorHandler('Uncaught'))->toBe('Uncaught');

});

it('returns message value on error not has "Uncaught" prefix and result is empty', function () {

allow('error_get_last')->toBeCalled()->andReturn([
'message' => 'Fatal',
]);

expect($this->listener->phpFatalErrorHandler('Fatal'))->toBe('Fatal');

});

});

describe('->execOnShutdown()', function () {

it('call error_get_last() and return nothing', function () {
it('call error_get_last() and return nothing and no result', function () {

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

});

it('call error_get_last() and return error', function () {
it('call error_get_last() and return nothing on result with "Uncaught" prefix', function () {

allow('error_get_last')->toBeCalled()->andReturn([
'type' => 8,
'message' => 'Undefined variable: a',
'message' => 'Uncaught',
'type' => 3,
]);
expect($this->listener->execOnShutdown())->toBeNull();

});

it('call error_get_last() and property_exists() after null check passed', function () {

allow('error_get_last')->toBeCalled()->andReturn([
'type' => 3,
'message' => 'class@anonymous cannot implement stdClass - it is not an interface',
'file' => '/var/www/zf/module/Application/Module.php',
'line' => 2
]);
Expand Down Expand Up @@ -368,12 +410,16 @@
$logging,
$this->renderer
);
allow('property_exists')->toBeCalled()->with($listener, 'request')->andReturn(false);
allow('property_exists')->toBeCalled()->with($listener, 'mvcEvent')->andReturn(true);

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

expect($listener->execOnShutdown())->toBeNull();

});

Expand Down Expand Up @@ -402,6 +448,15 @@

});

it('throws ErrorException on non excluded php errors', function () {

$closure = function () {
$this->listener->phpErrorHandler(\E_WARNING, 'warning', 'file.php', 1);
};
expect($closure)->toThrow(new \ErrorException('warning', 0, \E_WARNING, 'file.php', 1));

});

});

});
Loading

0 comments on commit 093f8e1

Please sign in to comment.