Completed
Branch master (a0c467)
by Tomáš
02:00
created

ControllerResolverTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 4
lcom 1
cbo 3
dl 8
loc 44
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Symplify\ControllerAutowire\Tests\HttpKernel\Controller;
4
5
use PHPUnit_Framework_TestCase;
6
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
10
use Symplify\ControllerAutowire\HttpKernel\Controller\ControllerResolver;
11
12
final class ControllerResolverTest extends PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var ControllerResolver
16
     */
17
    private $controllerResolver;
18
19
    protected function setUp()
20
    {
21
        $this->controllerResolver = $this->createControllerResolverWithMocks();
22
    }
23
24 View Code Duplication
    public function testGetController()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $request = new Request();
27
        $request->attributes->set('_controller', 'SomeController::someAction');
28
29
        $controller = $this->controllerResolver->getController($request);
30
        $this->assertNull($controller);
31
    }
32
33
    public function testGetArguments()
34
    {
35
        $this->assertNull(
36
            $this->controllerResolver->getArguments(new Request(), 'missing')
37
        );
38
    }
39
40
    /**
41
     * @return ControllerResolver
42
     */
43
    private function createControllerResolverWithMocks()
44
    {
45
        $parentControllerResolverMock = $this->prophesize(ControllerResolverInterface::class);
46
        $containerMock = $this->prophesize(ContainerInterface::class);
47
        $controllerNameParser = $this->prophesize(ControllerNameParser::class);
48
49
        return new ControllerResolver(
50
            $parentControllerResolverMock->reveal(),
51
            $containerMock->reveal(),
52
            $controllerNameParser->reveal()
53
        );
54
    }
55
}
56