-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'specific-error-exception'
* specific-error-exception: test clean up clean up cs cs clean up added ability to exclude specific PHP E_* error and Exception with specific message
- Loading branch information
Showing
10 changed files
with
316 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
spec/Fixture/config/autoload-for-specific-error-and-exception/error-hero-module.local.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
use Zend\Db\Adapter\AdapterInterface; | ||
|
||
return [ | ||
|
||
'db' => [ | ||
'username' => 'root', | ||
'password' => '', | ||
'driver' => 'Pdo', | ||
'dsn' => 'mysql:dbname=errorheromodule;host=127.0.0.1', | ||
'driver_options' => [ | ||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', | ||
], | ||
], | ||
|
||
'log' => [ | ||
'ErrorHeroModuleLogger' => [ | ||
'writers' => [ | ||
|
||
[ | ||
'name' => 'db', | ||
'options' => [ | ||
'db' => AdapterInterface::class, | ||
'table' => 'log', | ||
'column' => [ | ||
'timestamp' => 'date', | ||
'priority' => 'type', | ||
'message' => 'event', | ||
'extra' => [ | ||
'url' => 'url', | ||
'file' => 'file', | ||
'line' => 'line', | ||
'error_type' => 'error_type', | ||
'trace' => 'trace', | ||
'request_data' => 'request_data', | ||
], | ||
], | ||
], | ||
], | ||
|
||
], | ||
], | ||
], | ||
|
||
'error-hero-module' => [ | ||
'enable' => true, | ||
'display-settings' => [ | ||
|
||
// excluded php errors ( http://www.php.net/manual/en/errorfunc.constants.php ) | ||
'exclude-php-errors' => [ | ||
|
||
// can be specific error with specific message | ||
[\E_NOTICE, 'Undefined offset: 1'], | ||
|
||
], | ||
|
||
// excluded exceptions | ||
'exclude-exceptions' => [ | ||
|
||
// can be specific exception instance with specific error message | ||
[\Exception::class, 'a sample exception preview'], | ||
|
||
// or Error class | ||
[\Error::class, 'a sample error preview'], | ||
], | ||
|
||
// show or not error | ||
'display_errors' => 0, | ||
|
||
// if enable and display_errors = 0, the page will bring layout and view | ||
'template' => [ | ||
'layout' => 'layout/layout', | ||
'view' => 'error-hero-module/error-default' | ||
], | ||
|
||
// if enable and display_errors = 0, the console will bring message | ||
'console' => [ | ||
'message' => 'We have encountered a problem and we can not fulfill your request. An error report has been generated and sent to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience.', | ||
], | ||
|
||
], | ||
'logging-settings' => [ | ||
'same-error-log-time-range' => 86400, | ||
], | ||
'email-notification-settings' => [ | ||
// set to true to activate email notification on log error | ||
'enable' => false, | ||
|
||
// Zend\Mail\Message instance registered at service manager | ||
'mail-message' => 'YourMailMessageService', | ||
|
||
// Zend\Mail\Transport\TransportInterface instance registered at service manager | ||
'mail-transport' => 'YourMailTransportService', | ||
|
||
// email sender | ||
'email-from' => 'Sender Name <sender@host.com>', | ||
|
||
'email-to-send' => [ | ||
'developer1@foo.com', | ||
'developer2@foo.com', | ||
], | ||
], | ||
], | ||
]; |
110 changes: 110 additions & 0 deletions
110
spec/Integration/IntegrationViaErrorPreviewControllerForSpecificErrorAndExceptionSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace ErrorHeroModule\Spec; | ||
|
||
use ErrorHeroModule; | ||
use Zend\Console\Console; | ||
use Zend\Db\Adapter\AdapterInterface; | ||
use Zend\Db\ResultSet\ResultSet; | ||
use Zend\Db\TableGateway\TableGateway; | ||
use Zend\Mvc\Application; | ||
|
||
describe('Integration via ErrorPreviewController', function () { | ||
|
||
given('application', function () { | ||
|
||
Console::overrideIsConsole(false); | ||
|
||
$application = Application::init([ | ||
'modules' => [ | ||
'Zend\Router', | ||
'Zend\Db', | ||
'ErrorHeroModule', | ||
], | ||
'module_listener_options' => [ | ||
'config_glob_paths' => [ | ||
\realpath(__DIR__).'/../Fixture/config/autoload-for-specific-error-and-exception/error-hero-module.local.php', | ||
\realpath(__DIR__).'/../Fixture/config/module.local.php', | ||
], | ||
], | ||
]); | ||
|
||
$events = $application->getEventManager(); | ||
$serviceManager = $application->getServiceManager(); | ||
$serviceManager->get('SendResponseListener') | ||
->detach($events); | ||
|
||
return $application; | ||
|
||
}); | ||
|
||
describe('/error-preview', function() { | ||
|
||
it('empty as rely to original mvc process to handle', function() { | ||
|
||
$request = $this->application->getRequest(); | ||
$request->setMethod('GET'); | ||
$request->setUri('http://example.com/error-preview'); | ||
$request->setRequestUri('/error-preview'); | ||
|
||
\ob_start(); | ||
$this->application->run(); | ||
$content = \ob_get_clean(); | ||
|
||
expect(\ob_get_clean())->toBe(''); | ||
expect($this->application->getResponse()->getStatusCode())->toBe(500); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('/error-preview/notice', function() { | ||
|
||
it('empty as rely to original mvc process to handle', function() { | ||
|
||
@mkdir(__DIR__ . '/../Fixture/view/error-hero-module/error-preview', 0755, true); | ||
file_put_contents(__DIR__ . '/../Fixture/view/error-hero-module/error-preview/notice.phtml', ''); | ||
|
||
$request = $this->application->getRequest(); | ||
$request->setMethod('GET'); | ||
$request->setUri('http://example.com/error-preview/notice'); | ||
$request->setRequestUri('/error-preview/notice'); | ||
|
||
\ob_start(); | ||
$this->application->run(); | ||
$content = \ob_get_clean(); | ||
|
||
expect(\ob_get_clean())->toBe(''); | ||
// yes, excluded E_* error means it ignored, means it passed, means it is 200 status code | ||
expect($this->application->getResponse()->getStatusCode())->toBe(200); | ||
|
||
unlink(__DIR__ . '/../Fixture/view/error-hero-module/error-preview/notice.phtml'); | ||
rmdir(__DIR__ . '/../Fixture/view/error-hero-module/error-preview'); | ||
rmdir(__DIR__ . '/../Fixture/view/error-hero-module'); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('/error-preview/error', function() { | ||
|
||
it('empty as rely to original mvc process to handle', function() { | ||
|
||
$request = $this->application->getRequest(); | ||
$request->setMethod('GET'); | ||
$request->setUri('http://example.com/error-preview/error'); | ||
$request->setRequestUri('/error-preview/error'); | ||
|
||
\ob_start(); | ||
$this->application->run(); | ||
$content = \ob_get_clean(); | ||
|
||
expect(\ob_get_clean())->toBe(''); | ||
expect($this->application->getResponse()->getStatusCode())->toBe(500); | ||
|
||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.