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
|
|
|
|