|
169 | 169 |
|
170 | 170 | allow($this->router)->toReceive('match')->andReturn($match); |
171 | 171 | allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
| 172 | + allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about'); |
172 | 173 |
|
173 | 174 | allow($this->response)->toReceive('withStatus')->andReturn($this->response); |
174 | 175 |
|
|
187 | 188 | $listener->__invoke($this->request, $this->response, function () {}); |
188 | 189 |
|
189 | 190 | expect($this->response)->toReceive('withStatus')->with(308); |
| 191 | + expect($this->response)->toReceive('withHeader')->with('Location', 'https://example.com/about'); |
| 192 | + |
| 193 | + }); |
| 194 | + |
| 195 | + it('return Response with 308 status with include www prefix on http and match with configurable "add_www_prefix"', function () { |
| 196 | + |
| 197 | + Console::overrideIsConsole(false); |
| 198 | + $match = RouteResult::fromRoute(new Route('/about', 'About')); |
| 199 | + |
| 200 | + allow($this->router)->toReceive('match')->andReturn($match); |
| 201 | + allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
| 202 | + allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about'); |
| 203 | + |
| 204 | + allow($this->response)->toReceive('withStatus')->andReturn($this->response); |
| 205 | + |
| 206 | + $listener = new ForceHttps( |
| 207 | + [ |
| 208 | + 'enable' => true, |
| 209 | + 'force_all_routes' => true, |
| 210 | + 'strict_transport_security' => [ |
| 211 | + 'enable' => true, |
| 212 | + 'value' => 'max-age=31536000', |
| 213 | + ], |
| 214 | + 'add_www_prefix' => true, |
| 215 | + ], |
| 216 | + $this->router |
| 217 | + ); |
| 218 | + |
| 219 | + $listener->__invoke($this->request, $this->response, function () {}); |
| 220 | + |
| 221 | + expect($this->response)->toReceive('withStatus')->with(308); |
| 222 | + expect($this->response)->toReceive('withHeader')->with('Location', 'https://www.example.com/about'); |
190 | 223 |
|
191 | 224 | }); |
192 | 225 |
|
|
0 commit comments