1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use atoum; |
6
|
|
|
use Elasticsearch\Client; |
7
|
|
|
use GBProd\ElasticsearchExtraBundle\Handler\CreateIndexHandler; |
8
|
|
|
use GBProd\ElasticsearchExtraBundle\Handler\DeleteIndexHandler; |
9
|
|
|
use GBProd\ElasticsearchExtraBundle\Handler\PutIndexSettingsHandler; |
10
|
|
|
use GBProd\ElasticsearchExtraBundle\Handler\PutIndexMappingsHandler; |
11
|
|
|
use GBProd\ElasticsearchExtraBundle\Repository\ClientRepository; |
12
|
|
|
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tests for Extension class |
18
|
|
|
* |
19
|
|
|
* @author gbprod <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ElasticsearchExtraExtension extends atoum |
22
|
|
|
{ |
23
|
|
|
public function testLoadCreateServices() |
24
|
|
|
{ |
25
|
|
|
$container = new ContainerBuilder(); |
26
|
|
|
$this |
27
|
|
|
->given($extension = $this->newTestedInstance) |
28
|
|
|
->if($extension->load([], $container)) |
29
|
|
|
->then |
30
|
|
|
->object($container->get('gbprod.elasticsearch_extra.create_index_handler')) |
31
|
|
|
->isInstanceOf(CreateIndexHandler::class) |
32
|
|
|
->then |
33
|
|
|
->object($container->get('gbprod.elasticsearch_extra.client_repository')) |
34
|
|
|
->isInstanceOf(ClientRepository::class) |
35
|
|
|
->then |
36
|
|
|
->object($container->get('gbprod.elasticsearch_extra.index_configuration_repository')) |
37
|
|
|
->isInstanceOf(IndexConfigurationRepository::class) |
38
|
|
|
->then |
39
|
|
|
->object($container->get('gbprod.elasticsearch_extra.delete_index_handler')) |
40
|
|
|
->isInstanceOf(DeleteIndexHandler::class) |
41
|
|
|
->then |
42
|
|
|
->object($container->get('gbprod.elasticsearch_extra.put_index_settings_handler')) |
43
|
|
|
->isInstanceOf(PutIndexSettingsHandler::class) |
44
|
|
|
->then |
45
|
|
|
->object($container->get('gbprod.elasticsearch_extra.put_index_mappings_handler')) |
46
|
|
|
->isInstanceOf(PutIndexMappingsHandler::class) |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testLoadSetIndexConfigurations() |
51
|
|
|
{ |
52
|
|
|
$configs = [ |
53
|
|
|
[ |
54
|
|
|
'clients' => [ |
55
|
|
|
'my_client' => [ |
56
|
|
|
'indices' => [ |
57
|
|
|
'my_index' => [] |
58
|
|
|
] |
59
|
|
|
] |
60
|
|
|
] |
61
|
|
|
] |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$container = new ContainerBuilder(); |
65
|
|
|
$this |
66
|
|
|
->given($extension = $this->newTestedInstance) |
67
|
|
|
->if($extension->load($configs, $container)) |
68
|
|
|
->then |
69
|
|
|
->array( |
70
|
|
|
$container |
71
|
|
|
->getDefinition('gbprod.elasticsearch_extra.index_configuration_repository') |
72
|
|
|
->getArgument(0) |
73
|
|
|
) |
74
|
|
|
->isEqualTo([ |
75
|
|
|
'my_client' => [ |
76
|
|
|
'indices' => [ |
77
|
|
|
'my_index' => [] |
78
|
|
|
] |
79
|
|
|
] |
80
|
|
|
]) |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testLoadSetClients() |
85
|
|
|
{ |
86
|
|
|
$configs = [ |
87
|
|
|
[ |
88
|
|
|
'clients' => [ |
89
|
|
|
'my_client' => [ |
90
|
|
|
'indices' => [ |
91
|
|
|
'my_index' => [] |
92
|
|
|
] |
93
|
|
|
], |
94
|
|
|
'my_client_2' => [ |
95
|
|
|
'indices' => [ |
96
|
|
|
'my_index_2' => [] |
97
|
|
|
] |
98
|
|
|
] |
99
|
|
|
] |
100
|
|
|
] |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
$container = new ContainerBuilder(); |
104
|
|
|
$container->register( |
105
|
|
|
'm6web_elasticsearch.client.my_client', |
106
|
|
|
Client::class |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this |
110
|
|
|
->given($extension = $this->newTestedInstance) |
111
|
|
|
->if($extension->load($configs, $container)) |
112
|
|
|
->then |
113
|
|
|
->array( |
114
|
|
|
$argument = $container |
115
|
|
|
->getDefinition('gbprod.elasticsearch_extra.client_repository') |
116
|
|
|
->getArgument(0) |
117
|
|
|
) |
118
|
|
|
->isNotEmpty() |
119
|
|
|
->object($argument['my_client']) |
120
|
|
|
->isInstanceOf(Reference::class) |
121
|
|
|
->string($argument['my_client']->__toString()) |
122
|
|
|
->isEqualTo('m6web_elasticsearch.client.my_client') |
123
|
|
|
->object($argument['my_client_2']) |
124
|
|
|
->isInstanceOf(Reference::class) |
125
|
|
|
->string($argument['my_client_2']->__toString()) |
126
|
|
|
->isEqualTo('m6web_elasticsearch.client.my_client_2') |
127
|
|
|
; |
128
|
|
|
} |
129
|
|
|
} |