Skip to content

Commit 98741f9

Browse files
committed
use exit(0); to actually fix the overlap redirect
1 parent d0f2529 commit 98741f9

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

spec/Listener/ForceHttpsSpec.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use ForceHttpsModule\Listener\ForceHttps;
66
use Kahlan\Plugin\Double;
7+
use Kahlan\Plugin\Quit;
8+
use Kahlan\QuitException;
79
use Zend\Console\Console;
810
use Zend\EventManager\EventManagerInterface;
911
use Zend\Http\PhpEnvironment\Request;
@@ -80,6 +82,8 @@
8082
$this->request = Double::instance(['extends' => Request::class]);
8183
$this->uri = Double::instance(['extends' => Uri::class]);
8284
$this->routeMatch = Double::instance(['extends' => RouteMatch::class, 'methods' => '__construct']);
85+
86+
Quit::disable();
8387
});
8488

8589
context('on current scheme is https', function () {
@@ -159,7 +163,10 @@
159163
->with('SendResponseListener')
160164
->andReturn($this->sendResponseListener);
161165

162-
$listener->forceHttpsScheme($this->mvcEvent);
166+
$closure = function () use ($listener) {
167+
$listener->forceHttpsScheme($this->mvcEvent);
168+
};
169+
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));
163170

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

@@ -197,7 +204,10 @@
197204
->with('SendResponseListener')
198205
->andReturn($this->sendResponseListener);
199206

200-
$listener->forceHttpsScheme($this->mvcEvent);
207+
$closure = function () use ($listener) {
208+
$listener->forceHttpsScheme($this->mvcEvent);
209+
};
210+
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));
201211

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

@@ -233,7 +243,10 @@
233243
->with('SendResponseListener')
234244
->andReturn($this->sendResponseListener);
235245

236-
$listener->forceHttpsScheme($this->mvcEvent);
246+
$closure = function () use ($listener) {
247+
$listener->forceHttpsScheme($this->mvcEvent);
248+
};
249+
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));
237250

238251
expect($this->mvcEvent)->toReceive('getResponse');
239252
expect($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
@@ -271,7 +284,10 @@
271284
->with('SendResponseListener')
272285
->andReturn($this->sendResponseListener);
273286

274-
$listener->forceHttpsScheme($this->mvcEvent);
287+
$closure = function () use ($listener) {
288+
$listener->forceHttpsScheme($this->mvcEvent);
289+
};
290+
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));
275291

276292
expect($this->mvcEvent)->toReceive('getResponse');
277293
expect($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://www.example.com/about');
@@ -314,7 +330,10 @@
314330
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
315331
allow($this->response)->toReceive('send');
316332

317-
$listener->forceHttpsScheme($this->mvcEvent);
333+
$closure = function () use ($listener) {
334+
$listener->forceHttpsScheme($this->mvcEvent);
335+
};
336+
expect($closure)->toThrow(new QuitException('Exit statement occurred', 0));
318337

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

src/Listener/ForceHttps.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,7 @@ public function forceHttpsScheme(MvcEvent $e) : void
9999
$response->getHeaders()
100100
->addHeaderLine('Location', $httpsRequestUri);
101101
$response->send();
102+
103+
exit(0);
102104
}
103105
}

0 commit comments

Comments
 (0)