-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathAddLocatorCompilerPass.php
More file actions
58 lines (53 loc) · 3 KB
/
AddLocatorCompilerPass.php
File metadata and controls
58 lines (53 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Spy\TimelineBundle\Tests\Units\DependencyInjection\Compiler;
use atoum\atoum;
use Spy\TimelineBundle\DependencyInjection\Compiler\AddLocatorCompilerPass as TestedModel;
class AddLocatorCompilerPass extends atoum\test
{
public function testProcess()
{
//there are 4 (3 unique) config locator services so there should be only 3 addLocator calls
$configLocators = array('foo.service', 'bar.service');
$taggedServicesResult = array('baz.service' => array(), 'foo.service' => array());
//setup mocks
$this
->given($containerBuilder = new \mock\Symfony\Component\DependencyInjection\ContainerBuilder())
->and($this->mockGenerator->orphanize('__construct'))
->and($this->mockGenerator->shuntParentClassCalls())
->and($definition = new \mock\Symfony\Component\DependencyInjection\Definition())
//it asks for the locators parameter
->and($this->calling($containerBuilder)->hasParameter = function ($argument) {
switch ($argument) {
case "spy_timeline.filter.data_hydrator.locators_config":
return true;
}
})
->and($this->calling($containerBuilder)->getParameter = function ($argument) use ($configLocators) {
switch ($argument) {
case "spy_timeline.filter.data_hydrator.locators_config":
return $configLocators;
}
})
->and($this->calling($containerBuilder)->getDefinition = function () use ($definition) {
return $definition;
})
->and($this->calling($containerBuilder)->findTaggedServiceIds = function () use ($taggedServicesResult) {
return $taggedServicesResult;
})
->and($this->calling($definition)->addMethodCall = function () use ($definition) {
return $definition;
})
->and($compiler = new TestedModel())
->when($compiler->process($containerBuilder))
->then(
$this->mock($containerBuilder)->call('getParameter')->withArguments('spy_timeline.filter.data_hydrator.locators_config')->exactly(1)
->and($this->mock($containerBuilder)->call('findTaggedServiceIds')->withArguments('spy_timeline.filter.data_hydrator.locator')->exactly(1))
->and($this->mock($containerBuilder)->call('getDefinition')->withArguments('foo.service')->exactly(2))
->and($this->mock($containerBuilder)->call('getDefinition')->withArguments('bar.service')->exactly(1))
->and($this->mock($containerBuilder)->call('getDefinition')->withArguments('baz.service')->exactly(1))
//it only calls addlocator three times since foo.service is found twice and filtered
->and($this->mock($definition)->call('addMethodCall')->withArguments('addLocator', array($definition))->exactly(3))
)
;
}
}