ServiceTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A it_has_valid_alias() 0 3 1
A it_maps_service_with_same_id() 0 3 1
A it_allows_multiple_definitions() 0 3 1
A setUp() 0 4 1
A it_maps_services_with_custom_keys() 0 6 1
A readAnnotation() 0 5 1
A it_maps_services_with_variable_keys() 0 7 1
1
<?php
2
3
namespace Devmachine\Bundle\ServicesInjectorBundle\Tests\Configuration;
4
5
use Devmachine\Bundle\ServicesInjectorBundle\Configuration\Service;
6
use Doctrine\Common\Annotations\AnnotationReader;
7
8
class ServiceTest extends \PHPUnit_Framework_TestCase
9
{
10
    /** @var AnnotationReader */
11
    private $reader;
12
13
    public function setUp()
14
    {
15
        $this->reader = new AnnotationReader();
16
        $this->reader->addGlobalIgnoredName('test');
17
    }
18
19
    /**
20
     * @test
21
     */
22
    public function it_has_valid_alias()
23
    {
24
        $this->assertSame('services', (new Service([]))->getAliasName());
25
    }
26
27
    /**
28
     * @test
29
     */
30
    public function it_allows_multiple_definitions()
31
    {
32
        $this->assertTrue((new Service([]))->allowArray());
33
    }
34
35
    /**
36
     * @test
37
     *
38
     * @Service("twig")
39
     */
40
    public function it_maps_service_with_same_id()
41
    {
42
        $this->assertSame(['twig' => 'twig'], $this->readAnnotation(__FUNCTION__)->getAliases());
43
    }
44
45
    /**
46
     * @test
47
     *
48
     * @Service(url_generator="router", translator="translator")
49
     */
50
    public function it_maps_services_with_custom_keys()
51
    {
52
        $this->assertSame([
53
            'url_generator' => 'router',
54
            'translator'    => 'translator',
55
        ], $this->readAnnotation(__FUNCTION__)->getAliases());
56
    }
57
58
    /**
59
     * @test
60
     *
61
     * @Service({"twig", "url_generator"="router", "translator"})
62
     */
63
    public function it_maps_services_with_variable_keys()
64
    {
65
        $this->assertSame([
66
            'twig'          => 'twig',
67
            'url_generator' => 'router',
68
            'translator'    => 'translator',
69
        ], $this->readAnnotation(__FUNCTION__)->getAliases());
70
    }
71
72
    /**
73
     * @param string $methodName
74
     *
75
     * @return \Devmachine\Bundle\ServicesInjectorBundle\Configuration\Service
76
     */
77
    private function readAnnotation($methodName)
78
    {
79
        $rm = new \ReflectionMethod($this, $methodName);
80
81
        return $this->reader->getMethodAnnotation($rm, 'Devmachine\Bundle\ServicesInjectorBundle\Configuration\Service');
82
    }
83
}
84