|
8 | 8 | use Zend\EventManager\EventManagerInterface; |
9 | 9 | use Zend\Http\PhpEnvironment\Request; |
10 | 10 | use Zend\Http\PhpEnvironment\Response; |
| 11 | +use Zend\Mvc\Application; |
11 | 12 | use Zend\Mvc\MvcEvent; |
| 13 | +use Zend\Mvc\SendResponseListener; |
12 | 14 | use Zend\Router\RouteMatch; |
13 | 15 | use Zend\Uri\Uri; |
14 | 16 |
|
15 | 17 | describe('ForceHttps', function () { |
16 | 18 |
|
17 | | - describe('->attach()', function () { |
| 19 | + beforeAll(function () { |
| 20 | + $this->eventManager = Double::instance(['implements' => EventManagerInterface::class]); |
| 21 | + }); |
18 | 22 |
|
19 | | - beforeEach(function () { |
20 | | - $this->eventManager = Double::instance(['implements' => EventManagerInterface::class]); |
21 | | - }); |
| 23 | + describe('->attach()', function () { |
22 | 24 |
|
23 | 25 | it('not attach on route on console', function () { |
24 | 26 |
|
|
71 | 73 | describe('->forceHttpsScheme()', function () { |
72 | 74 |
|
73 | 75 | 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']); |
79 | 83 | }); |
80 | 84 |
|
81 | 85 | context('on current scheme is https', function () { |
|
149 | 153 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about'); |
150 | 154 | allow($this->response)->toReceive('send'); |
151 | 155 |
|
| 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 | + |
152 | 162 | $listener->forceHttpsScheme($this->mvcEvent); |
153 | 163 |
|
154 | 164 | expect($this->mvcEvent)->toReceive('getResponse'); |
|
181 | 191 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about'); |
182 | 192 | allow($this->response)->toReceive('send'); |
183 | 193 |
|
| 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 | + |
184 | 200 | $listener->forceHttpsScheme($this->mvcEvent); |
185 | 201 |
|
186 | 202 | expect($this->mvcEvent)->toReceive('getResponse'); |
|
211 | 227 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about'); |
212 | 228 | allow($this->response)->toReceive('send'); |
213 | 229 |
|
| 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 | + |
214 | 236 | $listener->forceHttpsScheme($this->mvcEvent); |
215 | 237 |
|
216 | 238 | expect($this->mvcEvent)->toReceive('getResponse'); |
|
243 | 265 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about'); |
244 | 266 | allow($this->response)->toReceive('send'); |
245 | 267 |
|
| 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 | + |
246 | 274 | $listener->forceHttpsScheme($this->mvcEvent); |
247 | 275 |
|
248 | 276 | expect($this->mvcEvent)->toReceive('getResponse'); |
|
276 | 304 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine') |
277 | 305 | ->with('Location', 'https://example.com/about') |
278 | 306 | ->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 | + |
279 | 314 | allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response); |
280 | 315 | allow($this->response)->toReceive('send'); |
281 | 316 |
|
|
304 | 339 | allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response); |
305 | 340 | allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Strict-Transport-Security: max-age=31536000'); |
306 | 341 |
|
| 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 | + |
307 | 348 | $listener->forceHttpsScheme($this->mvcEvent); |
308 | 349 |
|
309 | 350 | expect($this->mvcEvent)->toReceive('getResponse'); |
|
0 commit comments