|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\GBProd\ElasticsearchDataProviderBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DependencyInjection\Compiler\DataProviderCompilerPass; |
|
6
|
|
|
use GBProd\ElasticsearchDataProviderBundle\DataProvider\DataProvider; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Compiler path to register DataProviders |
|
12
|
|
|
* |
|
13
|
|
|
* @author gbprod <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class DataProviderCompilerPassTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
private $testedInstance; |
|
18
|
|
|
|
|
19
|
|
|
private $container; |
|
20
|
|
|
|
|
21
|
|
|
private $registryDefinition; |
|
22
|
|
|
|
|
23
|
|
|
public function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->testedInstance = new DataProviderCompilerPass(); |
|
26
|
|
|
$this->container = new ContainerBuilder(); |
|
27
|
|
|
$this->registryDefinition = new Definition(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testShouldRegisterTaggedDataProviders() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->container->setDefinition( |
|
33
|
|
|
'gbprod.elasticsearch_dataprovider.registry', |
|
34
|
|
|
$this->registryDefinition |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
$this->container->setDefinition( |
|
38
|
|
|
'data_provider.foo.bar', |
|
39
|
|
|
$this->newDataProviderDefinition('foo', 'bar') |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->container->setDefinition( |
|
43
|
|
|
'data_provider.bar.foo', |
|
44
|
|
|
$this->newDataProviderDefinition('fizz', 'buzz') |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->testedInstance->process($this->container); |
|
48
|
|
|
|
|
49
|
|
|
$calls = $this->registryDefinition->getMethodCalls(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals('addProvider', $calls[0][0]); |
|
52
|
|
|
$this->assertEquals('foo', $calls[0][1][1]); |
|
53
|
|
|
$this->assertEquals('bar', $calls[0][1][2]); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals('addProvider', $calls[1][0]); |
|
56
|
|
|
$this->assertEquals('fizz', $calls[1][1][1]); |
|
57
|
|
|
$this->assertEquals('buzz', $calls[1][1][2]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function newDataProviderDefinition($index, $type) |
|
61
|
|
|
{ |
|
62
|
|
|
$definition = new Definition(DataProvider::class); |
|
63
|
|
|
$definition->addTag( |
|
64
|
|
|
'elasticsearch_dataprovider.provider', |
|
65
|
|
|
['index' => $index, 'type' => $type] |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
return $definition; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testThrowsExceptionIfNotDataProvider() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->container->setDefinition( |
|
74
|
|
|
'gbprod.elasticsearch_dataprovider.registry', |
|
75
|
|
|
$this->registryDefinition |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$definition = new Definition(\stdClass::class); |
|
79
|
|
|
$definition->addTag( |
|
80
|
|
|
'elasticsearch_dataprovider.provider', |
|
81
|
|
|
['index' => 'foo', 'type' => 'bar'] |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->container->setDefinition( |
|
85
|
|
|
'data_provider.foo.bar', |
|
86
|
|
|
$definition |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$this->setExpectedException(\InvalidArgumentException::class); |
|
90
|
|
|
|
|
91
|
|
|
$this->testedInstance->process($this->container); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testThrowsExceptionIfBadTag() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->container->setDefinition( |
|
97
|
|
|
'gbprod.elasticsearch_dataprovider.registry', |
|
98
|
|
|
$this->registryDefinition |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$definition = new Definition(DataProvider::class); |
|
102
|
|
|
$definition->addTag( |
|
103
|
|
|
'elasticsearch_dataprovider.provider', |
|
104
|
|
|
['type' => $type] |
|
|
|
|
|
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
$this->container->setDefinition( |
|
108
|
|
|
'data_provider.foo.bar', |
|
109
|
|
|
$definition |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
|
|
$this->setExpectedException(\InvalidArgumentException::class); |
|
113
|
|
|
|
|
114
|
|
|
$this->testedInstance->process($this->container); |
|
115
|
|
|
} |
|
116
|
|
|
} |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.