Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[done] handling more fatal errors #54

Merged
merged 50 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e50eb89
handling more fatal errors at expressive env
samsonasik Sep 20, 2018
1b6e4f7
adding handling more fatal error to zend-mvc
samsonasik Sep 20, 2018
06857bd
remove unused fatal error delimiter string check
samsonasik Sep 20, 2018
84f6852
remove unused use statement
samsonasik Sep 20, 2018
2c13151
mvc results
samsonasik Sep 20, 2018
2b59c30
add request property
samsonasik Sep 20, 2018
4da5ac1
remove unused HeroAutoload class
samsonasik Sep 20, 2018
ca2966d
handle display fatal error at zend-mvc
samsonasik Sep 20, 2018
1624f90
phpstan
samsonasik Sep 20, 2018
ca46b5d
add result property
samsonasik Sep 20, 2018
2c094e1
else
samsonasik Sep 20, 2018
5a96e62
check
samsonasik Sep 20, 2018
05fb956
phpstan
samsonasik Sep 20, 2018
0b5376c
cs
samsonasik Sep 20, 2018
ad0b9c4
execOnShutdown check
samsonasik Sep 20, 2018
1ba17b2
kahlan config
samsonasik Sep 20, 2018
c42bb7d
add /error-preview/fatal page
samsonasik Sep 20, 2018
944748a
remove kahlan config to get reduced test
samsonasik Sep 20, 2018
de804e1
more integration tests for fatal error
samsonasik Sep 20, 2018
0d4a346
display trace in fatal error
samsonasik Sep 20, 2018
d7d4b0b
fatal error in /error-preview
samsonasik Sep 20, 2018
eb05207
Revert "more integration tests for fatal error"
samsonasik Sep 20, 2018
c37ec0e
keep logging in display error
samsonasik Sep 20, 2018
7a842e2
clean up return
samsonasik Sep 20, 2018
42b6d1a
check
samsonasik Sep 20, 2018
8e6c449
handle double input
samsonasik Sep 20, 2018
8c3633a
remove double display_errors check
samsonasik Sep 20, 2018
bc23419
fatal throw
samsonasik Sep 20, 2018
d434c0f
return
samsonasik Sep 20, 2018
f3d0028
Revert "Revert "more integration tests for fatal error""
samsonasik Sep 20, 2018
d6b0473
Revert "Revert "Revert "more integration tests for fatal error"""
samsonasik Sep 20, 2018
3bab234
test execOnShutdown for mvc
samsonasik Sep 20, 2018
ced9e5e
remove error-preview test
samsonasik Sep 20, 2018
46eb4fd
reply kahlan config
samsonasik Sep 20, 2018
e35a5d4
remove unneeded var displayFatalError
samsonasik Sep 20, 2018
ca6e424
var
samsonasik Sep 20, 2018
fb36817
keep using kahlan ~4.1.1 for compat json formatter test
samsonasik Sep 20, 2018
a5b661c
test exec shutdown on middleware
samsonasik Sep 20, 2018
9a3476a
almost
samsonasik Sep 20, 2018
709bc75
100% test
samsonasik Sep 20, 2018
c456b9a
mvc
samsonasik Sep 20, 2018
f1dc0fd
remove returns type declaration for phpFatalErrorHandler callback
samsonasik Sep 20, 2018
daeb244
remove unneeded http_response_code(500)
samsonasik Sep 20, 2018
9a41bd3
Revert "remove returns type declaration for phpFatalErrorHandler call…
samsonasik Sep 20, 2018
7209983
error type check
samsonasik Sep 20, 2018
5e46e43
test
samsonasik Sep 20, 2018
49e8432
clean up throw
samsonasik Sep 21, 2018
fe81084
return buffer on empty result
samsonasik Sep 21, 2018
69579e9
test
samsonasik Sep 21, 2018
fcca9c2
clean up
samsonasik Sep 21, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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