|
39 | 39 |
|
40 | 40 | it('not redirect on router not match', function (): void { |
41 | 41 |
|
42 | | - $match = RouteResult::fromRouteFailure(null); |
43 | | - allow($this->router)->toReceive('match')->andReturn($match); |
44 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
| 42 | + $routeResult = RouteResult::fromRouteFailure(null); |
| 43 | + |
| 44 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 45 | + |
| 46 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 47 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
45 | 48 |
|
46 | 49 | $listener = new ForceHttps(['enable' => true], $this->router); |
47 | 50 |
|
|
56 | 59 |
|
57 | 60 | it('not redirect on router not match and config allow_404 is false', function (): void { |
58 | 61 |
|
59 | | - $match = RouteResult::fromRouteFailure(null); |
60 | | - allow($this->router)->toReceive('match')->andReturn($match); |
61 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
| 62 | + $routeResult = RouteResult::fromRouteFailure(null); |
| 63 | + |
| 64 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 65 | + |
| 66 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 67 | + allow($this->uri)->toReceive('__toString')->andReturn('http://example.com/404'); |
| 68 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
62 | 69 |
|
63 | 70 | $listener = new ForceHttps( |
64 | 71 | [ |
|
79 | 86 |
|
80 | 87 | it('not redirect on https and match but no strict_transport_security config', function (): void { |
81 | 88 |
|
82 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 89 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
83 | 90 |
|
84 | | - allow($this->router)->toReceive('match')->andReturn($match); |
| 91 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
85 | 92 |
|
86 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https'); |
| 93 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 94 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about'); |
| 95 | + allow($this->uri)->toReceive('getScheme')->andReturn('https'); |
87 | 96 |
|
88 | 97 | $listener = new ForceHttps(['enable' => true, 'force_all_routes' => true], $this->router); |
89 | 98 |
|
|
98 | 107 |
|
99 | 108 | it('not redirect on http and match, with force_all_routes is false and matched route name not in force_specific_routes config', function (): void { |
100 | 109 |
|
101 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
102 | | - allow($this->router)->toReceive('match')->andReturn($match); |
| 110 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 111 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
103 | 112 |
|
104 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
| 113 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 114 | + allow($this->uri)->toReceive('__toString')->andReturn('http://example.com/about'); |
| 115 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
105 | 116 |
|
106 | 117 | $listener = new ForceHttps( |
107 | 118 | [ |
|
127 | 138 |
|
128 | 139 | it('not redirect on https and match, with strict_transport_security config, but disabled', function (): void { |
129 | 140 |
|
130 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 141 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
131 | 142 |
|
132 | | - allow($this->router)->toReceive('match')->andReturn($match); |
| 143 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
133 | 144 |
|
134 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https'); |
| 145 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 146 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about'); |
| 147 | + allow($this->uri)->toReceive('getScheme')->andReturn('https'); |
135 | 148 |
|
136 | 149 | $listener = new ForceHttps( |
137 | 150 | [ |
|
157 | 170 |
|
158 | 171 | it('not redirect on https and match, with strict_transport_security config, and enabled', function (): void { |
159 | 172 |
|
160 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 173 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
161 | 174 |
|
162 | | - allow($this->router)->toReceive('match')->andReturn($match); |
163 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('https'); |
| 175 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 176 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 177 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about'); |
| 178 | + allow($this->uri)->toReceive('getScheme')->andReturn('https'); |
164 | 179 |
|
165 | 180 | $listener = new ForceHttps( |
166 | 181 | [ |
|
186 | 201 |
|
187 | 202 | it('return Response with 308 status on http and match', function (): void { |
188 | 203 |
|
189 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 204 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 205 | + |
| 206 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
190 | 207 |
|
191 | | - allow($this->router)->toReceive('match')->andReturn($match); |
192 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
193 | | - allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about'); |
| 208 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 209 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
| 210 | + allow($this->uri)->toReceive('withScheme')->andReturn($this->uri); |
| 211 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about'); |
194 | 212 |
|
195 | 213 | $handler = Double::instance(['implements' => RequestHandlerInterface::class]); |
196 | 214 | allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response); |
|
217 | 235 |
|
218 | 236 | it('return Response with 308 status on http and not match, but allow_404 is true', function (): void { |
219 | 237 |
|
220 | | - $match = RouteResult::fromRouteFailure(null); |
| 238 | + $routeResult = RouteResult::fromRouteFailure(null); |
221 | 239 |
|
222 | | - allow($this->router)->toReceive('match')->andReturn($match); |
223 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
224 | | - allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/404'); |
| 240 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 241 | + |
| 242 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 243 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
| 244 | + allow($this->uri)->toReceive('withScheme')->andReturn($this->uri); |
| 245 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/404'); |
225 | 246 |
|
226 | 247 | $handler = Double::instance(['implements' => RequestHandlerInterface::class]); |
227 | 248 | allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response); |
|
244 | 265 |
|
245 | 266 | it('return Response with 308 status with include www prefix on http and match with configurable "add_www_prefix"', function (): void { |
246 | 267 |
|
247 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 268 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
248 | 269 |
|
249 | | - allow($this->router)->toReceive('match')->andReturn($match); |
250 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
251 | | - allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://example.com/about'); |
| 270 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 271 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 272 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
| 273 | + allow($this->uri)->toReceive('withScheme')->andReturn($this->uri); |
| 274 | + allow($this->uri)->toReceive('__toString')->andReturn('https://example.com/about'); |
252 | 275 |
|
253 | 276 | $handler = Double::instance(['implements' => RequestHandlerInterface::class]); |
254 | 277 | allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response); |
|
276 | 299 |
|
277 | 300 | it('return Response with 308 status with remove www prefix on http and match with configurable "remove_www_prefix"', function (): void { |
278 | 301 |
|
279 | | - $match = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
| 302 | + $routeResult = RouteResult::fromRoute(new Route('/about', Double::instance(['implements' => MiddlewareInterface::class]))); |
280 | 303 |
|
281 | | - allow($this->request)->toReceive('getUri', '__toString')->andReturn('http://www.example.com/about'); |
282 | | - allow($this->router)->toReceive('match')->andReturn($match); |
283 | | - allow($this->request)->toReceive('getUri', 'getScheme')->andReturn('http'); |
284 | | - allow($this->request)->toReceive('getUri', 'withScheme', '__toString')->andReturn('https://www.example.com/about'); |
285 | | - |
286 | | - allow($this->response)->toReceive('withStatus')->andReturn($this->response); |
287 | | - $handler = Double::instance(['implements' => RequestHandlerInterface::class]); |
288 | | - allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response); |
| 304 | + allow($this->router)->toReceive('match')->andReturn($routeResult); |
| 305 | + allow($this->request)->toReceive('getUri')->andReturn($this->uri); |
| 306 | + allow($this->uri)->toReceive('getScheme')->andReturn('http'); |
| 307 | + allow($this->uri)->toReceive('withScheme')->andReturn($this->uri); |
| 308 | + allow($this->uri)->toReceive('__toString')->andReturn('https://www.example.com/about'); |
289 | 309 |
|
290 | 310 | $handler = Double::instance(['implements' => RequestHandlerInterface::class]); |
291 | 311 | allow($handler)->toReceive('handle')->with($this->request)->andReturn($this->response); |
|
300 | 320 | 'enable' => true, |
301 | 321 | 'value' => 'max-age=31536000', |
302 | 322 | ], |
303 | | - 'add_www_prefix' => false, |
304 | 323 | 'remove_www_prefix' => true, |
305 | 324 | ], |
306 | 325 | $this->router |
307 | 326 | ); |
308 | | - |
309 | 327 | $listener->process($this->request, $handler); |
310 | 328 |
|
311 | 329 | expect($this->response)->toReceive('withStatus')->with(308); |
|
0 commit comments