Skip to content

Commit d3f2385

Browse files
committed
Merge branch 'console-argv'
* console-argv: zend-mvc-console require command class_alias fix command "php" console preview class alias fix and its spec console controller zf3 preview name fix console preview exclude zf2 console controller from test syntax error fix adding error preview console controllers readme preview update better Console information with include scriptname and args
2 parents e406484 + 2bc8c0d commit d3f2385

11 files changed

+240
-143
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,34 @@ return [
217217
Give it a try!
218218
--------------
219219

220+
*Web Access*
221+
220222
| URl | Preview For |
221223
|--------------------------------------|--------------|
222224
| http://yourzfapp/error-preview | Exception |
223225
| http://yourzfapp/error-preview/error | Error |
224226

227+
You will get the following page if display_errors config is 0:
228+
229+
![error preview in web](https://cloud.githubusercontent.com/assets/459648/21668589/d4fdadac-d335-11e6-95aa-5a8cfa3f8e4b.png)
230+
231+
*Console Access*
232+
233+
> If you use zend-mvc v3, you need to have `zendframework/zend-mvc-console` in your vendor, if you don't have, you can install it via command:
234+
235+
> ```
236+
> composer require zendframework/zend-mvc-console --sort-packages
237+
> ```
238+
239+
| Command | Preview For |
240+
|------------------------------------------|--------------|
241+
| php public/index.php error-preview | Exception |
242+
| php public/index.php error-preview error | Error |
243+
244+
You will get the following page if display_errors config is 0:
245+
246+
![error preview in console](https://cloud.githubusercontent.com/assets/459648/21669141/8e7690f0-d33b-11e6-99c7-eed4f1ab7edb.png)
247+
225248
Contributing
226249
------------
227250
Contributions are very welcome. Please read [CONTRIBUTING.md](https://github.com/samsonasik/ErrorHeroModule/blob/master/CONTRIBUTING.md)

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
"doctrine/doctrine-orm-module": "^1.1",
2828
"kahlan/kahlan": "^3.0.0",
2929
"satooshi/php-coveralls": "^1.0",
30-
"zendframework/zend-mvc": "^2.5|^3.0"
30+
"zendframework/zend-mvc": "^2.5|^3.0",
31+
"zendframework/zend-mvc-console": "^1.1"
32+
},
33+
"suggest": {
34+
"zendframework/zend-mvc-console": "^1.1 for zend-mvc ^3.0 usage to be able to use Console Controller"
3135
},
3236
"autoload": {
3337
"psr-4": {

config/module.config.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,43 @@
1010
'controllers' => [
1111
'invokables' => [
1212
// sm v2 compat
13-
Controller\ErrorPreviewController::class => Controller\ErrorPreviewController::class,
13+
Controller\ErrorPreviewController::class => Controller\ErrorPreviewController::class,
14+
Controller\ErrorPreviewConsoleController::class => Controller\ErrorPreviewConsoleController::class,
1415
],
1516
'factories' => [
1617
// sm v3
17-
Controller\ErrorPreviewController::class => InvokableFactory::class,
18+
Controller\ErrorPreviewController::class => InvokableFactory::class,
19+
Controller\ErrorPreviewConsoleController::class => InvokableFactory::class,
1820
],
1921
],
2022

2123
'router' => [
2224
'routes' => [
25+
2326
'error-preview' => [
2427
'type' => 'Segment',
2528
'options' => [
2629
'route' => '/error-preview[/][:action]',
2730
'defaults' => [
2831
'controller' => Controller\ErrorPreviewController::class,
29-
'action' => 'exception',
32+
'action' => 'exception',
33+
],
34+
],
35+
],
36+
37+
],
38+
],
39+
40+
'console' => [
41+
'router' => [
42+
'routes' => [
43+
'error-preview-console' => [
44+
'options' => [
45+
'route' => 'error-preview [<action>]',
46+
'defaults' => [
47+
'controller' => Controller\ErrorPreviewConsoleController::class,
48+
'action' => 'exception'
49+
],
3050
],
3151
],
3252
],
@@ -38,7 +58,7 @@
3858
Log\LoggerAbstractServiceFactory::class,
3959
],
4060
'factories' => [
41-
Listener\Mvc::class => Listener\MvcFactory::class,
61+
Listener\Mvc::class => Listener\MvcFactory::class,
4262
Handler\Logging::class => Handler\LoggingFactory::class,
4363
],
4464
],
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace ErrorHeroModule\Spec;
4+
5+
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
6+
7+
describe('ErrorPreviewConsoleController', function () {
8+
9+
given('controller', function () {
10+
11+
return new ErrorPreviewConsoleController();
12+
13+
});
14+
15+
describe('->exceptionAction()', function() {
16+
17+
it('throw Exception', function() {
18+
19+
$controller = $this->controller;
20+
$closure = function() use ($controller) {
21+
$controller->exceptionAction();
22+
};
23+
expect($closure)->toThrow(new \Exception('a sample error preview'));
24+
25+
});
26+
27+
});
28+
29+
describe('->errorAction()', function() {
30+
31+
it('Error', function() {
32+
33+
skipIf(PHP_MAJOR_VERSION < 7);
34+
35+
try {
36+
$controller = $this->controller;
37+
$controller->errorAction();
38+
} catch (\Throwable $error) {
39+
expect($error)->toBeAnInstanceOf(\Throwable::class);
40+
}
41+
42+
});
43+
44+
});
45+
46+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace ErrorHeroModule\Spec;
4+
5+
use ErrorHeroModule;
6+
use ErrorHeroModule\Controller\ErrorPreviewConsoleController;
7+
use Kahlan\Plugin\Quit;
8+
use Kahlan\QuitException;
9+
use Zend\Console\Console;
10+
use Zend\Db\ResultSet\ResultSet;
11+
use Zend\Db\TableGateway\TableGateway;
12+
use Zend\Log;
13+
use Zend\Mvc\Application;
14+
15+
describe('Integration via ErrorPreviewConsoleController', function () {
16+
17+
given('application', function () {
18+
19+
Console::overrideIsConsole(true);
20+
21+
$application = Application::init([
22+
'modules' => [
23+
'Zend\Router',
24+
'Zend\Db',
25+
'ErrorHeroModule',
26+
],
27+
'module_listener_options' => [
28+
'config_glob_paths' => [
29+
realpath(__DIR__).'/Fixture/autoload/{{,*.}global,{,*.}local}.php',
30+
],
31+
],
32+
]);
33+
34+
$events = $application->getEventManager();
35+
$serviceManager = $application->getServiceManager();
36+
$serviceManager->get('SendResponseListener')
37+
->detach($events);
38+
39+
$db = $serviceManager->get('Zend\Db\Adapter\Adapter');
40+
$tableGateway = new TableGateway('log', $db, null, new ResultSet());
41+
$tableGateway->delete([]);
42+
43+
return $application;
44+
45+
});
46+
47+
describe('/error-preview', function() {
48+
49+
it('show error page', function() {
50+
51+
skipIf(PHP_MAJOR_VERSION < 7);
52+
53+
Quit::disable();
54+
55+
$_SERVER['argv'] = [
56+
__FILE__,
57+
'error-preview',
58+
'controller' => ErrorPreviewConsoleController::class,
59+
'action' => 'exception',
60+
];
61+
62+
ob_start();
63+
$closure = function () {
64+
$this->application->run();
65+
};
66+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
67+
$content = ob_get_clean();
68+
69+
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
70+
71+
});
72+
73+
});
74+
75+
describe('/error-preview/error', function() {
76+
77+
it('show error page', function() {
78+
79+
skipIf(PHP_MAJOR_VERSION < 7);
80+
81+
Quit::disable();
82+
83+
$_SERVER['argv'] = [
84+
__FILE__,
85+
'error-preview',
86+
'controller' => ErrorPreviewConsoleController::class,
87+
'action' => 'error',
88+
];
89+
90+
ob_start();
91+
$closure = function () {
92+
$this->application->run();
93+
};
94+
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
95+
$content = ob_get_clean();
96+
97+
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
98+
99+
});
100+
});
101+
102+
});

spec/IntegrationViaErrorPreviewControllerForIdempotentSpec.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -81,49 +81,6 @@
8181

8282
});
8383

84-
it('show error console message in console env', function() {
85-
86-
Console::overrideIsConsole(true);
87-
88-
skipIf(PHP_MAJOR_VERSION < 7);
89-
90-
Quit::disable();
91-
92-
allow('php_uname')->toBeCalled()->andReturn('Apples-MacBook-Pro.local');
93-
94-
$application = Application::init([
95-
'modules' => [
96-
'Zend\Router',
97-
'Zend\Db',
98-
'ErrorHeroModule',
99-
],
100-
'module_listener_options' => [
101-
'config_glob_paths' => [
102-
realpath(__DIR__).'/Fixture/autoload/{{,*.}global,{,*.}local}.php',
103-
],
104-
],
105-
]);
106-
107-
$events = $application->getEventManager();
108-
$serviceManager = $application->getServiceManager();
109-
$serviceManager->get('SendResponseListener')
110-
->detach($events);
111-
112-
$request = $application->getRequest();
113-
$request->setMethod('GET');
114-
$request->setUri('/error-preview');
115-
116-
ob_start();
117-
$closure = function () use ($application) {
118-
$application->run();
119-
};
120-
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
121-
$content = ob_get_clean();
122-
123-
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
124-
125-
});
126-
12784
});
12885

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

spec/IntegrationViaErrorPreviewControllerSpec.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,47 +67,6 @@
6767

6868
});
6969

70-
it('show error console message in console env', function() {
71-
72-
Console::overrideIsConsole(true);
73-
74-
skipIf(PHP_MAJOR_VERSION < 7);
75-
76-
Quit::disable();
77-
78-
$application = Application::init([
79-
'modules' => [
80-
'Zend\Router',
81-
'Zend\Db',
82-
'ErrorHeroModule',
83-
],
84-
'module_listener_options' => [
85-
'config_glob_paths' => [
86-
realpath(__DIR__).'/Fixture/autoload/{{,*.}global,{,*.}local}.php',
87-
],
88-
],
89-
]);
90-
91-
$events = $application->getEventManager();
92-
$serviceManager = $application->getServiceManager();
93-
$serviceManager->get('SendResponseListener')
94-
->detach($events);
95-
96-
$request = $application->getRequest();
97-
$request->setMethod('GET');
98-
$request->setUri('/error-preview');
99-
100-
ob_start();
101-
$closure = function () use ($application) {
102-
$application->run();
103-
};
104-
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
105-
$content = ob_get_clean();
106-
107-
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
108-
109-
});
110-
11170
});
11271

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

spec/IntegrationViaErrorPreviewControllerWithEnableSendMailSpec.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,47 +67,6 @@
6767

6868
});
6969

70-
it('show error console message in console env', function() {
71-
72-
Console::overrideIsConsole(true);
73-
74-
skipIf(PHP_MAJOR_VERSION < 7);
75-
76-
Quit::disable();
77-
78-
$application = Application::init([
79-
'modules' => [
80-
'Zend\Router',
81-
'Zend\Db',
82-
'ErrorHeroModule',
83-
],
84-
'module_listener_options' => [
85-
'config_glob_paths' => [
86-
realpath(__DIR__).'/Fixture/autoload/{{,*.}global,{,*.}local}.php',
87-
],
88-
],
89-
]);
90-
91-
$events = $application->getEventManager();
92-
$serviceManager = $application->getServiceManager();
93-
$serviceManager->get('SendResponseListener')
94-
->detach($events);
95-
96-
$request = $application->getRequest();
97-
$request->setMethod('GET');
98-
$request->setUri('/error-preview');
99-
100-
ob_start();
101-
$closure = function () use ($application) {
102-
$application->run();
103-
};
104-
expect($closure)->toThrow(new QuitException('Exit statement occurred', -1));
105-
$content = ob_get_clean();
106-
107-
expect($content)->toContain('|We have encountered a problem and we can not fulfill your request');
108-
109-
});
110-
11170
});
11271

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

0 commit comments

Comments
 (0)