1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\Tests\Units\ElasticsearchExtraBundle\Handler; |
4
|
|
|
|
5
|
|
|
use atoum; |
6
|
|
|
use mock\Elasticsearch\Client; |
7
|
|
|
use mock\Elasticsearch\Namespaces\IndicesNamespace; |
8
|
|
|
use mock\GBProd\ElasticsearchExtraBundle\Repository\ClientRepository; |
9
|
|
|
use mock\GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests for PutIndexSettingsHandler |
13
|
|
|
* |
14
|
|
|
* @author gbprod <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class PutIndexSettingsHandler extends atoum |
17
|
|
|
{ |
18
|
|
|
public function testHandle() |
19
|
|
|
{ |
20
|
|
|
$config = [ |
21
|
|
|
'settings' => [ |
22
|
|
|
'awesome' => 'config' |
23
|
|
|
], |
24
|
|
|
'foo' => 'bar', |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
$this |
28
|
|
|
->given($config) |
29
|
|
|
->and($indices = $this->newIndices()) |
30
|
|
|
->and($client = $this->newClient($indices)) |
31
|
|
|
->and($configRepository = $this->newConfigRepository('my_index', $config)) |
32
|
|
|
->and($this->newTestedInstance($configRepository)) |
33
|
|
|
->if($this->testedInstance->handle($client, 'my_index')) |
34
|
|
|
->then |
35
|
|
|
->mock($indices) |
36
|
|
|
->call('putSettings') |
37
|
|
|
->withArguments( |
38
|
|
|
[ |
39
|
|
|
'index' => 'my_index', |
40
|
|
|
'body' => [ |
41
|
|
|
'settings' => ['awesome' => 'config'] |
42
|
|
|
], |
43
|
|
|
] |
44
|
|
|
) |
45
|
|
|
->once() |
46
|
|
|
; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function newIndices() |
50
|
|
|
{ |
51
|
|
|
$this->mockGenerator->shuntParentClassCalls(); |
52
|
|
|
$this->mockGenerator->orphanize('__construct'); |
53
|
|
|
|
54
|
|
|
return new IndicesNamespace(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function newClient($indices) |
58
|
|
|
{ |
59
|
|
|
$this->mockGenerator->shuntParentClassCalls(); |
60
|
|
|
$this->mockGenerator->orphanize('__construct'); |
61
|
|
|
|
62
|
|
|
$client = new Client(); |
63
|
|
|
|
64
|
|
|
$this->calling($client)->indices = function() use ($indices) { |
65
|
|
|
return $indices; |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
return $client; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function newConfigRepository($index, $config) |
72
|
|
|
{ |
73
|
|
|
$this->mockGenerator->shuntParentClassCalls(); |
74
|
|
|
$this->mockGenerator->orphanize('__construct'); |
75
|
|
|
|
76
|
|
|
$configRepository = new IndexConfigurationRepository(); |
77
|
|
|
|
78
|
|
|
$this->calling($configRepository)->get = |
79
|
|
|
function($indexParam) use ($index, $config) { |
80
|
|
|
if ($index == $indexParam) { |
81
|
|
|
return $config; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
; |
87
|
|
|
|
88
|
|
|
$this->mockGenerator->unshuntParentClassCalls(); |
89
|
|
|
|
90
|
|
|
return $configRepository; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|