@@ 327-367 (lines=41) @@ | ||
324 | /** |
|
325 | * @test |
|
326 | */ |
|
327 | public function shouldRedirectFromException() |
|
328 | { |
|
329 | $controller = new GenericExceptionResponseController($this->controllerHelper, $this->argumentBuilder, [ |
|
330 | 'inner-controller' => $this->innerController, |
|
331 | 'inner-controller-method' => "serialize", |
|
332 | 'exception-responses' => [ |
|
333 | InvalidArgumentException::class => [ |
|
334 | 'redirect-route' => 'some_redirect_route', |
|
335 | 'redirect-route-parameters' => [ |
|
336 | 'foo' => 'bar' |
|
337 | ] |
|
338 | ] |
|
339 | ] |
|
340 | ]); |
|
341 | ||
342 | $this->innerController->method("serialize")->will($this->returnCallback( |
|
343 | function () { |
|
344 | throw new InvalidArgumentException("Lorem ipsum!"); |
|
345 | } |
|
346 | )); |
|
347 | ||
348 | /** @var RedirectResponse $redirectResponse */ |
|
349 | $redirectResponse = $this->createMock(RedirectResponse::class); |
|
350 | ||
351 | $this->controllerHelper->expects($this->once())->method('handleException'); |
|
352 | $this->controllerHelper->expects($this->once())->method('redirectToRoute')->with( |
|
353 | $this->equalTo('some_redirect_route'), |
|
354 | $this->equalTo([]), |
|
355 | $this->equalTo(301) |
|
356 | )->willReturn($redirectResponse); |
|
357 | ||
358 | /** @var Request $request */ |
|
359 | $request = $this->createMock(Request::class); |
|
360 | $request->attributes = $this->createMock(ParameterBag::class); |
|
361 | $request->attributes->method('get')->willReturn([]); |
|
362 | ||
363 | /** @var Response $response */ |
|
364 | $response = $controller->executeInnerControllerSafely($request); |
|
365 | ||
366 | $this->assertSame($redirectResponse, $response); |
|
367 | } |
|
368 | ||
369 | /** |
|
370 | * @test |
|
@@ 372-414 (lines=43) @@ | ||
369 | /** |
|
370 | * @test |
|
371 | */ |
|
372 | public function shouldBeCallableByInvokingController() |
|
373 | { |
|
374 | $controller = new GenericExceptionResponseController($this->controllerHelper, $this->argumentBuilder, [ |
|
375 | 'inner-controller' => $this->innerController, |
|
376 | 'inner-controller-method' => "serialize", |
|
377 | 'exception-responses' => [ |
|
378 | InvalidArgumentException::class => [ |
|
379 | 'redirect-route' => 'some_redirect_route', |
|
380 | 'redirect-route-parameters' => [ |
|
381 | 'foo' => 'bar' |
|
382 | ] |
|
383 | ] |
|
384 | ] |
|
385 | ]); |
|
386 | ||
387 | $this->innerController->method("serialize")->will($this->returnCallback( |
|
388 | function () { |
|
389 | throw new InvalidArgumentException("Lorem ipsum!"); |
|
390 | } |
|
391 | )); |
|
392 | ||
393 | /** @var RedirectResponse $redirectResponse */ |
|
394 | $redirectResponse = $this->createMock(RedirectResponse::class); |
|
395 | ||
396 | $this->controllerHelper->expects($this->once())->method('handleException'); |
|
397 | $this->controllerHelper->expects($this->once())->method('redirectToRoute')->with( |
|
398 | $this->equalTo('some_redirect_route'), |
|
399 | $this->equalTo([]), |
|
400 | $this->equalTo(301) |
|
401 | )->willReturn($redirectResponse); |
|
402 | ||
403 | /** @var Request $request */ |
|
404 | $request = $this->createMock(Request::class); |
|
405 | $request->attributes = $this->createMock(ParameterBag::class); |
|
406 | $request->attributes->method('get')->willReturn([]); |
|
407 | ||
408 | $this->controllerHelper->method('getCurrentRequest')->willReturn($request); |
|
409 | ||
410 | /** @var Response $response */ |
|
411 | $response = $controller(); |
|
412 | ||
413 | $this->assertSame($redirectResponse, $response); |
|
414 | } |
|
415 | ||
416 | /** |
|
417 | * @test |