|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Tests\Innmind\Neo4jBundle\DependencyInjection\Compiler; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Neo4jBundle\DependencyInjection\{ |
|
7
|
|
|
Compiler\RegistrableServicePass, |
|
8
|
|
|
InnmindNeo4jExtension |
|
9
|
|
|
}; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\{ |
|
11
|
|
|
ContainerBuilder, |
|
12
|
|
|
Reference, |
|
13
|
|
|
Definition, |
|
14
|
|
|
Compiler\CompilerPassInterface |
|
15
|
|
|
}; |
|
16
|
|
|
|
|
17
|
|
|
class RegistrableServicePassTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testProcess() |
|
20
|
|
|
{ |
|
21
|
|
|
$c = new ContainerBuilder; |
|
22
|
|
|
(new InnmindNeo4jExtension)->load([], $c); |
|
23
|
|
|
$c->setDefinition( |
|
24
|
|
|
'foo', |
|
25
|
|
|
(new Definition) |
|
26
|
|
|
->addTag('innmind_neo4j.identity.generator', ['class' => 'stdClass']) |
|
27
|
|
|
); |
|
28
|
|
|
$this->assertSame( |
|
29
|
|
|
null, |
|
30
|
|
|
($p = new RegistrableServicePass( |
|
31
|
|
|
'innmind_neo4j.generators', |
|
32
|
|
|
'innmind_neo4j.identity.generator' |
|
33
|
|
|
)) |
|
34
|
|
|
->process($c) |
|
35
|
|
|
); |
|
36
|
|
|
$this->assertInstanceOf(CompilerPassInterface::class, $p); |
|
37
|
|
|
|
|
38
|
|
|
$definition = $c->getDefinition('innmind_neo4j.generators'); |
|
39
|
|
|
$calls = $definition->getMethodCalls(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame(1, count($calls)); |
|
42
|
|
|
$this->assertSame('register', $calls[0][0]); |
|
43
|
|
|
$this->assertSame('stdClass', $calls[0][1][0]); |
|
44
|
|
|
$this->assertInstanceOf(Reference::class, $calls[0][1][1]); |
|
45
|
|
|
$this->assertSame('foo', (string) $calls[0][1][1]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @expectedException Innmind\Neo4jBundle\Exception\RuntimeException |
|
50
|
|
|
* @expectedExceptionMessage The class attribute must be defined |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testThrowWhenNoClassForGenerator() |
|
53
|
|
|
{ |
|
54
|
|
|
$c = new ContainerBuilder; |
|
55
|
|
|
(new InnmindNeo4jExtension)->load([], $c); |
|
56
|
|
|
$c->setDefinition( |
|
57
|
|
|
'foo', |
|
58
|
|
|
(new Definition) |
|
59
|
|
|
->addTag('innmind_neo4j.identity.generator') |
|
60
|
|
|
); |
|
61
|
|
|
(new RegistrableServicePass( |
|
62
|
|
|
'innmind_neo4j.generators', |
|
63
|
|
|
'innmind_neo4j.identity.generator' |
|
64
|
|
|
)) |
|
65
|
|
|
->process($c); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testProcessRepositoryFactoryConfigurator() |
|
69
|
|
|
{ |
|
70
|
|
|
$c = new ContainerBuilder; |
|
71
|
|
|
(new InnmindNeo4jExtension)->load([], $c); |
|
72
|
|
|
$c->setDefinition( |
|
73
|
|
|
'foo', |
|
74
|
|
|
(new Definition) |
|
75
|
|
|
->addTag('innmind_neo4j.repository', ['class' => 'stdClass']) |
|
76
|
|
|
); |
|
77
|
|
|
$this->assertSame( |
|
78
|
|
|
null, |
|
79
|
|
|
($p = new RegistrableServicePass( |
|
80
|
|
|
'innmind_neo4j.repository_factory.configurator', |
|
81
|
|
|
'innmind_neo4j.repository' |
|
82
|
|
|
)) |
|
83
|
|
|
->process($c) |
|
84
|
|
|
); |
|
85
|
|
|
$this->assertInstanceOf(CompilerPassInterface::class, $p); |
|
86
|
|
|
|
|
87
|
|
|
$definition = $c->getDefinition('innmind_neo4j.repository_factory.configurator'); |
|
88
|
|
|
$calls = $definition->getMethodCalls(); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertSame(1, count($calls)); |
|
91
|
|
|
$this->assertSame('register', $calls[0][0]); |
|
92
|
|
|
$this->assertSame('stdClass', $calls[0][1][0]); |
|
93
|
|
|
$this->assertInstanceOf(Reference::class, $calls[0][1][1]); |
|
94
|
|
|
$this->assertSame('foo', (string) $calls[0][1][1]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @expectedException Innmind\Neo4jBundle\Exception\RuntimeException |
|
99
|
|
|
* @expectedExceptionMessage The class attribute must be defined |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testThrowWhenNoClassForRepository() |
|
102
|
|
|
{ |
|
103
|
|
|
$c = new ContainerBuilder; |
|
104
|
|
|
(new InnmindNeo4jExtension)->load([], $c); |
|
105
|
|
|
$c->setDefinition( |
|
106
|
|
|
'foo', |
|
107
|
|
|
(new Definition) |
|
108
|
|
|
->addTag('innmind_neo4j.repository') |
|
109
|
|
|
); |
|
110
|
|
|
(new RegistrableServicePass( |
|
111
|
|
|
'innmind_neo4j.repository_factory.configurator', |
|
112
|
|
|
'innmind_neo4j.repository' |
|
113
|
|
|
)) |
|
114
|
|
|
->process($c); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|