|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ChannelBundle\Tests\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
15
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasMethodCallConstraint; |
|
16
|
|
|
use Sylius\Bundle\ChannelBundle\DependencyInjection\Compiler\CompositeChannelContextPass; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Kamil Kokot <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class CompositeChannelContextPassTest extends AbstractCompilerPassTestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
*/ |
|
29
|
|
|
public function it_collects_tagged_channel_contexts() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->setDefinition('sylius.context.channel.composite', new Definition()); |
|
32
|
|
|
$this->setDefinition( |
|
33
|
|
|
'sylius.context.channel.tagged_one', |
|
34
|
|
|
(new Definition())->addTag('sylius.context.channel') |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
$this->compile(); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertContainerBuilderHasAlias('sylius.context.channel', 'sylius.context.channel.composite'); |
|
40
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
41
|
|
|
'sylius.context.channel', |
|
42
|
|
|
'addContext', |
|
43
|
|
|
[new Reference('sylius.context.channel.tagged_one')] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @test |
|
49
|
|
|
*/ |
|
50
|
|
|
public function it_collects_tagged_channel_contexts_with_priority() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->setDefinition('sylius.context.channel.composite', new Definition()); |
|
53
|
|
|
$this->setDefinition( |
|
54
|
|
|
'sylius.context.channel.tagged_one', |
|
55
|
|
|
(new Definition())->addTag('sylius.context.channel', ['priority' => 42]) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$this->compile(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertContainerBuilderHasAlias('sylius.context.channel', 'sylius.context.channel.composite'); |
|
61
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
62
|
|
|
'sylius.context.channel', |
|
63
|
|
|
'addContext', |
|
64
|
|
|
[new Reference('sylius.context.channel.tagged_one'), 42] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @test |
|
70
|
|
|
*/ |
|
71
|
|
|
public function it_does_not_add_method_calls_to_the_overriding_service_if_the_composite_service_is_overridden() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->setDefinition('sylius.context.channel', new Definition()); |
|
74
|
|
|
$this->setDefinition('sylius.context.channel.composite', new Definition()); |
|
75
|
|
|
$this->setDefinition( |
|
76
|
|
|
'sylius.context.channel.tagged_one', |
|
77
|
|
|
(new Definition())->addTag('sylius.context.channel') |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$this->compile(); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertContainerBuilderNotHasServiceDefinitionWithMethodCall( |
|
83
|
|
|
'sylius.context.channel', |
|
84
|
|
|
'addContext', |
|
85
|
|
|
[new Reference('sylius.context.channel.tagged_one')] |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @test |
|
91
|
|
|
*/ |
|
92
|
|
|
public function it_still_adds_method_calls_to_composite_context_even_if_it_was_overridden() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->setDefinition('sylius.context.channel', new Definition()); |
|
95
|
|
|
$this->setDefinition('sylius.context.channel.composite', new Definition()); |
|
96
|
|
|
$this->setDefinition( |
|
97
|
|
|
'sylius.context.channel.tagged_one', |
|
98
|
|
|
(new Definition())->addTag('sylius.context.channel') |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$this->compile(); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
|
104
|
|
|
'sylius.context.channel.composite', |
|
105
|
|
|
'addContext', |
|
106
|
|
|
[new Reference('sylius.context.channel.tagged_one')] |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
114
|
|
|
{ |
|
115
|
|
|
$container->addCompilerPass(new CompositeChannelContextPass()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param string $serviceId |
|
120
|
|
|
* @param string $method |
|
121
|
|
|
* @param array $arguments |
|
122
|
|
|
*/ |
|
123
|
|
|
private function assertContainerBuilderNotHasServiceDefinitionWithMethodCall($serviceId, $method, $arguments) |
|
124
|
|
|
{ |
|
125
|
|
|
$definition = $this->container->findDefinition($serviceId); |
|
126
|
|
|
|
|
127
|
|
|
self::assertThat( |
|
128
|
|
|
$definition, |
|
129
|
|
|
new \PHPUnit_Framework_Constraint_Not(new DefinitionHasMethodCallConstraint($method, $arguments)) |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|