1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\Artprima\QueryFilterBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Artprima\QueryFilterBundle\DependencyInjection\Compiler\AddQueryBuilderConditionPass; |
6
|
|
|
use Artprima\QueryFilterBundle\Query\ConditionManager; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class AddQueryBuilderConditionPass |
14
|
|
|
* |
15
|
|
|
* @author Denis Voytyuk <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class AddQueryBuilderConditionPassTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var AddQueryBuilderConditionPass |
21
|
|
|
*/ |
22
|
|
|
private $pass; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ContainerBuilder |
26
|
|
|
*/ |
27
|
|
|
private $container; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Definition |
31
|
|
|
*/ |
32
|
|
|
private $managerDefinition; |
33
|
|
|
|
34
|
|
|
public function setUp(): void |
35
|
|
|
{ |
36
|
|
|
$this->pass = new AddQueryBuilderConditionPass(); |
37
|
|
|
$this->container = new ContainerBuilder(); |
38
|
|
|
$this->managerDefinition = new Definition(); |
39
|
|
|
$this->container->setDefinition(ConditionManager::class, $this->managerDefinition); |
40
|
|
|
$this->container->setParameter('query_filter_bundle.disabled_conditions', []); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @doesNotPerformAssertions |
45
|
|
|
*/ |
46
|
|
|
public function testProcessNoOpNoManager() |
47
|
|
|
{ |
48
|
|
|
$this->container->removeDefinition(ConditionManager::class); |
49
|
|
|
$this->pass->process($this->container); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testProcessNoOpNoTaggedServices() |
53
|
|
|
{ |
54
|
|
|
$this->pass->process($this->container); |
55
|
|
|
self::assertCount(0, $this->managerDefinition->getMethodCalls()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testProcessAddsTaggedServices() |
59
|
|
|
{ |
60
|
|
|
$condition1 = new Definition(); |
61
|
|
|
$condition1->setTags([ |
62
|
|
|
'proxy_query_builder.condition' => [ |
63
|
|
|
[ |
64
|
|
|
'condition' => 'bar', |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
$condition2 = new Definition(); |
70
|
|
|
$condition2->setTags([ |
71
|
|
|
'proxy_query_builder.condition' => [ |
72
|
|
|
[ |
73
|
|
|
'condition' => 'baz', |
74
|
|
|
], |
75
|
|
|
], |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
$this->container->setDefinition('condition_one', $condition1); |
79
|
|
|
$this->container->setDefinition('condition_two', $condition2); |
80
|
|
|
|
81
|
|
|
$this->container->setParameter('query_filter_bundle.disabled_conditions', []); |
82
|
|
|
|
83
|
|
|
$this->pass->process($this->container); |
84
|
|
|
|
85
|
|
|
$methodCalls = $this->managerDefinition->getMethodCalls(); |
86
|
|
|
self::assertCount(2, $methodCalls); |
87
|
|
|
self::assertEquals(['add', [new Reference('condition_one'), 'bar']], $methodCalls[0]); |
88
|
|
|
self::assertEquals(['add', [new Reference('condition_two'), 'baz']], $methodCalls[1]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testProcessDisabledTaggedServices() |
92
|
|
|
{ |
93
|
|
|
$condition1 = new Definition(); |
94
|
|
|
$condition1->setTags([ |
95
|
|
|
'proxy_query_builder.condition' => [ |
96
|
|
|
[ |
97
|
|
|
'condition' => 'bar', |
98
|
|
|
], |
99
|
|
|
], |
100
|
|
|
]); |
101
|
|
|
|
102
|
|
|
$condition2 = new Definition(); |
103
|
|
|
$condition2->setTags([ |
104
|
|
|
'proxy_query_builder.condition' => [ |
105
|
|
|
[ |
106
|
|
|
'condition' => 'baz', |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
]); |
110
|
|
|
|
111
|
|
|
$condition3 = new Definition(); |
112
|
|
|
$condition3->setTags([ |
113
|
|
|
'proxy_query_builder.condition' => [ |
114
|
|
|
[ |
115
|
|
|
'condition' => 'foo', |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
]); |
119
|
|
|
|
120
|
|
|
$this->container->setDefinition('condition_one', $condition1); |
121
|
|
|
$this->container->setDefinition('condition_two', $condition2); |
122
|
|
|
$this->container->setDefinition('condition_three', $condition3); |
123
|
|
|
|
124
|
|
|
$this->container->setParameter('query_filter_bundle.disabled_conditions', ['bar', 'baz']); |
125
|
|
|
|
126
|
|
|
$this->pass->process($this->container); |
127
|
|
|
|
128
|
|
|
$methodCalls = $this->managerDefinition->getMethodCalls(); |
129
|
|
|
self::assertCount(1, $methodCalls); |
130
|
|
|
self::assertEquals(['add', [new Reference('condition_three'), 'foo']], $methodCalls[0]); |
131
|
|
|
} |
132
|
|
|
} |