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