Code Duplication    Length = 39-41 lines in 2 locations

tests/unit/Controllers/GenericExceptionResponseControllerTest.php 2 locations

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