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

CompleteAliasingTest::testGetContainerAwareController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %
Metric Value
dl 11
loc 11
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Symplify\ControllerAutowire\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Tests\Controller;
9
use Symplify\ControllerAutowire\HttpKernel\Controller\ControllerResolver;
10
use Symplify\ControllerAutowire\Tests\AliasingBundle\Controller\AliasController;
11
use Symplify\ControllerAutowire\Tests\CompleteTestSource\Scan\ContainerAwareController;
12
use Symplify\ControllerAutowire\Tests\HttpKernel\Controller\ControllerFinderSource\SomeController;
13
use Symplify\ControllerAutowire\Tests\HttpKernel\Controller\ControllerFinderSource\SomeService;
14
15
final class CompleteAliasingTest extends PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @var ControllerResolver
19
     */
20
    private $controllerResolver;
21
22
    protected function setUp()
23
    {
24
        $kernel = new AppKernelWithAlias('another_env', true);
25
        $kernel->boot();
26
27
        $this->controllerResolver = $kernel->getContainer()
28
            ->get('default.controller_resolver');
29
    }
30
31
    public function testControllerResolver()
32
    {
33
        $this->assertInstanceOf(ControllerResolver::class, $this->controllerResolver);
34
    }
35
36 View Code Duplication
    public function testGetAutowiredController()
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...
37
    {
38
        $request = new Request();
39
        $request->attributes->set('_controller', SomeController::class.'::someAction');
40
41
        /** @var SomeController $controller */
42
        $controller = $this->controllerResolver->getController($request)[0];
43
44
        $this->assertInstanceOf(SomeController::class, $controller);
45
        $this->assertInstanceOf(SomeService::class, $controller->getSomeService());
46
    }
47
48 View Code Duplication
    public function testGetContainerAwareController()
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...
49
    {
50
        $request = new Request();
51
        $request->attributes->set('_controller', ContainerAwareController::class.'::someAction');
52
53
        /** @var ContainerAwareController $controller */
54
        $controller = $this->controllerResolver->getController($request)[0];
55
56
        $this->assertInstanceOf(ContainerAwareController::class, $controller);
57
        $this->assertInstanceOf(ContainerInterface::class, $controller->getContainer());
58
    }
59
60 View Code Duplication
    public function testGetControllerServiceMissing()
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...
61
    {
62
        $request = new Request();
63
        $request->attributes->set('_controller', 'some.missing.controller.service:someAction');
64
65
        $controller = $this->controllerResolver->getController($request);
66
        $this->assertNull($controller);
67
    }
68
69 View Code Duplication
    public function testGetControllerAliasConfig()
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...
70
    {
71
        $request = new Request();
72
        $request->attributes->set('_controller', 'AliasingBundle:Alias:some');
73
74
        $controller = $this->controllerResolver->getController($request)[0];
75
        $this->assertInstanceOf(AliasController::class, $controller);
76
    }
77
}
78