Skip to content

Commit

Permalink
Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 4, 2017
1 parent beee247 commit a056976
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 18 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"require": {
"php": "^5.6|^7.0",
"seld/jsonlint": "^1.5",
"zendframework/zend-console": "^2.5",
"zendframework/zend-db": "^2.5",
"zendframework/zend-hydrator": "^1.0|^2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

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' => 'Zend\Db\Adapter\Adapter',
'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
'exclude-php-errors' => [
E_USER_DEPRECATED
],

// 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 send to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience.',
],

'ajax' => [
'message' => 'We have encountered a problem and we can not fulfill your request. An error report has been generated and send 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',
],
],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace ErrorHeroModule;

use Zend\Log;
use Zend\ServiceManager\Factory\InvokableFactory;

return [

'controllers' => [
'factories' => [
Controller\ErrorPreviewController::class => InvokableFactory::class,
],
],

'router' => [
'routes' => [
'error-preview' => [
'type' => 'Segment',
'options' => [
'route' => '/error-preview[/][:action]',
'defaults' => [
'controller' => Controller\ErrorPreviewController::class,
'action' => 'exception',
],
],
],
],
],

'service_manager' => [
'abstract_factories' => [
Log\LoggerAbstractServiceFactory::class,
],
'factories' => [
Listener\Mvc::class => Listener\MvcFactory::class,
Handler\Logging::class => Handler\LoggingFactory::class,
],
],

'view_manager' => [
'template_path_stack' => [
__DIR__.'/../view',
],
],

];
10 changes: 5 additions & 5 deletions spec/IntegrationViaErrorPreviewControllerForIdempotentSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand All @@ -74,7 +74,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down Expand Up @@ -117,7 +117,7 @@
$closure = function () use ($application) {
$application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
Expand All @@ -142,7 +142,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand All @@ -163,7 +163,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toBe(<<<json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace ErrorHeroModule\Spec\Integration;

use ErrorHeroModule;
use ErrorHeroModule\Controller\ErrorPreviewController;
use Kahlan\Plugin\Quit;
use Kahlan\QuitException;
use Zend\Console\Console;
use Zend\Http\PhpEnvironment\Request;
use Zend\Mvc\Application;

describe('Integration via ErrorPreviewController for XmlHttpRequest', 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/autoload-for-xmlhttprequest-with-non-json-message/{{,*.}global,{,*.}local}.php',
],
],
]);

$events = $application->getEventManager();
$serviceManager = $application->getServiceManager();
$serviceManager->get('SendResponseListener')
->detach($events);

return $application;

});

describe('/error-preview', function() {

it('show error page', function() {

skipIf(PHP_MAJOR_VERSION < 7);
Quit::disable();

$request = $this->application->getRequest();
$request->setMethod('GET');
$request->setUri('/error-preview');

allow(Request::class)->toReceive('isXmlHttpRequest')->andReturn(true);

ob_start();
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toBe('We have encountered a problem and we can not fulfill your request. An error report has been generated and send to the support team and someone will attend to this problem urgently. Please try again later. Thank you for your patience.');

});

});

});
6 changes: 3 additions & 3 deletions spec/IntegrationViaErrorPreviewControllerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down Expand Up @@ -101,7 +101,7 @@
$closure = function () use ($application) {
$application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
Expand All @@ -126,7 +126,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down Expand Up @@ -101,7 +101,7 @@
$closure = function () use ($application) {
$application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
Expand All @@ -126,7 +126,7 @@
$closure = function () {
$this->application->run();
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
Expand Down
4 changes: 2 additions & 2 deletions spec/Listener/MvcSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
$closure = function () use ($listener, $mvcEvent) {
$listener->exceptionError($mvcEvent);
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('We have encountered a problem');
Expand All @@ -261,7 +261,7 @@
$closure = function () use ($mvcEvent) {
$this->listener->exceptionError($mvcEvent);
};
expect($closure)->toThrow(new QuitException());
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
$content = ob_get_clean();

expect($content)->toContain('We have encountered a problem');
Expand Down
Loading

0 comments on commit a056976

Please sign in to comment.