Skip to content

Commit 029186a

Browse files
committed
Merge branch 'fix-overlap-redirect-dispatch'
2 parents b171a96 + a704d93 commit 029186a

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ before_script:
88
- mkdir -p build/logs
99
- composer self-update
1010
- travis_retry composer install --prefer-source --no-interaction
11-
- composer global require --dev phpstan/phpstan
11+
- composer require --dev phpstan/phpstan
1212
- composer dump-autoload -o
1313

1414
script:
15-
- ~/.composer/vendor/bin/phpstan analyse src/ --level=max
15+
- bin/phpstan analyse src/ --level=max
1616
- bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml
1717
- bin/php-coveralls -v --exclude-no-stmt
1818

spec/Listener/ForceHttpsSpec.php

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
use Zend\EventManager\EventManagerInterface;
99
use Zend\Http\PhpEnvironment\Request;
1010
use Zend\Http\PhpEnvironment\Response;
11+
use Zend\Mvc\Application;
1112
use Zend\Mvc\MvcEvent;
13+
use Zend\Mvc\SendResponseListener;
1214
use Zend\Router\RouteMatch;
1315
use Zend\Uri\Uri;
1416

1517
describe('ForceHttps', function () {
1618

17-
describe('->attach()', function () {
19+
beforeAll(function () {
20+
$this->eventManager = Double::instance(['implements' => EventManagerInterface::class]);
21+
});
1822

19-
beforeEach(function () {
20-
$this->eventManager = Double::instance(['implements' => EventManagerInterface::class]);
21-
});
23+
describe('->attach()', function () {
2224

2325
it('not attach on route on console', function () {
2426

@@ -71,11 +73,13 @@
7173
describe('->forceHttpsScheme()', function () {
7274

7375
beforeEach(function () {
74-
$this->mvcEvent = Double::instance(['extends' => MvcEvent::class, 'methods' => '__construct']);
75-
$this->response = Double::instance(['extends' => Response::class]);
76-
$this->request = Double::instance(['extends' => Request::class]);
77-
$this->uri = Double::instance(['extends' => Uri::class]);
78-
$this->routeMatch = Double::instance(['extends' => RouteMatch::class, 'methods' => '__construct']);
76+
$this->mvcEvent = Double::instance(['extends' => MvcEvent::class, 'methods' => '__construct']);
77+
$this->application = Double::instance(['extends' => Application::class, 'methods' => '__construct']);
78+
$this->sendResponseListener = Double::instance(['extends' => SendResponseListener::class, 'methods' => '__construct']);
79+
$this->response = Double::instance(['extends' => Response::class]);
80+
$this->request = Double::instance(['extends' => Request::class]);
81+
$this->uri = Double::instance(['extends' => Uri::class]);
82+
$this->routeMatch = Double::instance(['extends' => RouteMatch::class, 'methods' => '__construct']);
7983
});
8084

8185
context('on current scheme is https', function () {
@@ -149,6 +153,12 @@
149153
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
150154
allow($this->response)->toReceive('send');
151155

156+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
157+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
158+
allow($this->application)->toReceive('getServiceManager', 'get')
159+
->with('SendResponseListener')
160+
->andReturn($this->sendResponseListener);
161+
152162
$listener->forceHttpsScheme($this->mvcEvent);
153163

154164
expect($this->mvcEvent)->toReceive('getResponse');
@@ -181,6 +191,12 @@
181191
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
182192
allow($this->response)->toReceive('send');
183193

194+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
195+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
196+
allow($this->application)->toReceive('getServiceManager', 'get')
197+
->with('SendResponseListener')
198+
->andReturn($this->sendResponseListener);
199+
184200
$listener->forceHttpsScheme($this->mvcEvent);
185201

186202
expect($this->mvcEvent)->toReceive('getResponse');
@@ -211,6 +227,12 @@
211227
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
212228
allow($this->response)->toReceive('send');
213229

230+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
231+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
232+
allow($this->application)->toReceive('getServiceManager', 'get')
233+
->with('SendResponseListener')
234+
->andReturn($this->sendResponseListener);
235+
214236
$listener->forceHttpsScheme($this->mvcEvent);
215237

216238
expect($this->mvcEvent)->toReceive('getResponse');
@@ -243,6 +265,12 @@
243265
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
244266
allow($this->response)->toReceive('send');
245267

268+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
269+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
270+
allow($this->application)->toReceive('getServiceManager', 'get')
271+
->with('SendResponseListener')
272+
->andReturn($this->sendResponseListener);
273+
246274
$listener->forceHttpsScheme($this->mvcEvent);
247275

248276
expect($this->mvcEvent)->toReceive('getResponse');
@@ -276,6 +304,13 @@
276304
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')
277305
->with('Location', 'https://example.com/about')
278306
->andReturn($this->response);
307+
308+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
309+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
310+
allow($this->application)->toReceive('getServiceManager', 'get')
311+
->with('SendResponseListener')
312+
->andReturn($this->sendResponseListener);
313+
279314
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
280315
allow($this->response)->toReceive('send');
281316

@@ -304,6 +339,12 @@
304339
allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response);
305340
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Strict-Transport-Security: max-age=31536000');
306341

342+
allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
343+
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
344+
allow($this->application)->toReceive('getServiceManager', 'get')
345+
->with('SendResponseListener')
346+
->andReturn($this->sendResponseListener);
347+
307348
$listener->forceHttpsScheme($this->mvcEvent);
308349

309350
expect($this->mvcEvent)->toReceive('getResponse');

src/Listener/ForceHttps.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public function forceHttpsScheme(MvcEvent $e) : void
8888
$httpsRequestUri = $this->getFinalhttpsRequestUri($uriString);
8989
}
9090

91+
$application = $e->getApplication();
92+
$events = $application->getEventManager();
93+
$serviceManager = $application->getServiceManager();
94+
$serviceManager->get('SendResponseListener')
95+
->detach($events);
96+
9197
// 308 keeps headers, request method, and request body
9298
$response->setStatusCode(308);
9399
$response->getHeaders()

0 commit comments

Comments
 (0)