DevmachineServicesInjectorBundleTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A it_injects_locator_into_second_action() 0 14 1
A setUpBeforeClass() 0 3 1
A setUp() 0 9 1
A it_injects_locator_into_first_action() 0 12 1
A createRequest() 0 3 1
A it_throws_exception_on_third_action() 0 8 1
A getKernelClass() 0 3 1
1
<?php
2
3
namespace Devmachine\Bundle\ServicesInjectorBundle\Tests\Functional;
4
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * @group functional
11
 */
12
class DevmachineServicesInjectorBundleTest extends KernelTestCase
13
{
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject
16
     */
17
    private $serviceLocator;
18
19
    public static function setUpBeforeClass()
20
    {
21
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader('class_exists');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
22
    }
23
24
    public function setUp()
25
    {
26
        static::bootKernel();
27
28
        $this->serviceLocator = $this->getMock('Devmachine\Bundle\ServicesInjectorBundle\ServiceLocator\ServiceLocator');
29
30
        static::$kernel->getContainer()->set(
31
            'devmachine_services_injector.service_locator.container',
32
            $this->serviceLocator
33
        );
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function it_injects_locator_into_first_action()
40
    {
41
        $this->serviceLocator
42
            ->expects($this->exactly(2))
43
            ->method('get')
44
            ->withConsecutive(
45
                [$this->equalTo('twig')],
46
                [$this->equalTo('translator')]
47
            )
48
        ;
49
50
        static::$kernel->handle($this->createRequest('firstAction'));
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function it_injects_locator_into_second_action()
57
    {
58
        $this->serviceLocator
59
            ->expects($this->exactly(4))
60
            ->method('get')
61
            ->withConsecutive(
62
                [$this->equalTo('twig')],
63
                [$this->equalTo('form.factory')],
64
                [$this->equalTo('router')],
65
                [$this->equalTo('translator')]
66
            )
67
        ;
68
69
        static::$kernel->handle($this->createRequest('secondAction'));
70
    }
71
72
    /**
73
     * @test
74
     *
75
     * @expectedException \InvalidArgumentException
76
     * @expectedExceptionMessage Service with alias "translator" is not registered.
77
     */
78
    public function it_throws_exception_on_third_action()
79
    {
80
        $this->serviceLocator
81
            ->expects($this->never())
82
            ->method('get')
83
        ;
84
85
        static::$kernel->handle($this->createRequest('thirdAction'));
86
    }
87
88
    protected static function getKernelClass()
89
    {
90
        return __NAMESPACE__.'\\TestKernel';
91
    }
92
93
    /**
94
     * @param string $methodName
95
     *
96
     * @return Request
97
     */
98
    private function createRequest($methodName)
99
    {
100
        return new Request([], [], ['_controller' => [new TestController(), $methodName]]);
101
    }
102
}
103