Skip to content

Commit 4477f78

Browse files
committed
no ned Zend\Http\Header\Cookie instance creation when request->getCookie() not instance of Cookie, which is false, set cookie_data to [] directly
1 parent 560a6d3 commit 4477f78

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace ErrorHeroModule\Spec;
4+
5+
use ErrorHeroModule;
6+
use ErrorHeroModule\Controller\ErrorPreviewController;
7+
use Zend\Console\Console;
8+
use Zend\Db\Adapter\Adapter;
9+
use Zend\Db\ResultSet\ResultSet;
10+
use Zend\Db\TableGateway\TableGateway;
11+
use Zend\Http\Header\Cookie;
12+
use Zend\Mvc\Application;
13+
14+
describe('Integration via ErrorPreviewController for has cookie', function () {
15+
16+
given('application', function () {
17+
18+
Console::overrideIsConsole(false);
19+
20+
$application = Application::init([
21+
'modules' => [
22+
'Zend\Router',
23+
'Zend\Db',
24+
'ErrorHeroModule',
25+
],
26+
'module_listener_options' => [
27+
'config_glob_paths' => [
28+
realpath(__DIR__).'/../Fixture/config/autoload/error-hero-module.local.php',
29+
realpath(__DIR__).'/../Fixture/config/module.local.php',
30+
],
31+
],
32+
]);
33+
34+
$events = $application->getEventManager();
35+
$serviceManager = $application->getServiceManager();
36+
37+
$db = $serviceManager->get(Adapter::class);
38+
$tableGateway = new TableGateway('log', $db, null, new ResultSet());
39+
$tableGateway->delete([]);
40+
41+
$application->getRequest()->setCookies(['foo' => 'value']);
42+
43+
return $application;
44+
45+
});
46+
47+
describe('/error-preview', function() {
48+
49+
it('show error page', function() {
50+
51+
$request = $this->application->getRequest();
52+
$request->setMethod('GET');
53+
$request->setUri('http://example.com/error-preview');
54+
$request->setRequestUri('/error-preview');
55+
56+
ob_start();
57+
$this->application->run();
58+
$content = ob_get_clean();
59+
60+
expect($content)->toContain('<title>Error');
61+
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
62+
expect($this->application->getResponse()->getStatusCode())->toBe(500);
63+
64+
});
65+
66+
});
67+
68+
describe('/error-preview/error', function() {
69+
70+
it('show error page', function() {
71+
72+
$request = $this->application->getRequest();
73+
$request->setMethod('GET');
74+
$request->setUri('http://example.com/error-preview/error');
75+
$request->setRequestUri('/error-preview/error');
76+
77+
ob_start();
78+
$this->application->run();
79+
$content = ob_get_clean();
80+
81+
expect($content)->toContain('<title>Error');
82+
expect($content)->toContain('<p>We have encountered a problem and we can not fulfill your request');
83+
expect($this->application->getResponse()->getStatusCode())->toBe(500);
84+
85+
});
86+
});
87+
88+
});

src/Handler/Logging.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ private function getRequestData(RequestInterface $request) : array
116116
$files_data = $request->getFiles()->toArray();
117117
$cookie = $request->getCookie();
118118

119-
if ($cookie === false) {
120-
$cookie = new Cookie([]);
119+
if ($cookie instanceof Cookie) {
120+
$cookie_data = $cookie->getArrayCopy();
121+
} else {
122+
$cookie_data = [];
121123
}
122124

123-
Assertion::isInstanceOf($cookie, Cookie::class);
124-
$cookie_data = $cookie->getArrayCopy();
125-
126125
return [
127126
'request_method' => $request_method,
128127
'query_data' => $query_data,

0 commit comments

Comments
 (0)