1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the FOSElasticaBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace FOS\ElasticaBundle\Tests\Command; |
12
|
|
|
|
13
|
|
|
use FOS\ElasticaBundle\Command\CreateCommand; |
14
|
|
|
use FOS\ElasticaBundle\Configuration\ConfigManager; |
15
|
|
|
use FOS\ElasticaBundle\Configuration\IndexConfig; |
16
|
|
|
use FOS\ElasticaBundle\Elastica\Index; |
17
|
|
|
use FOS\ElasticaBundle\Index\AliasProcessor; |
18
|
|
|
use FOS\ElasticaBundle\Index\IndexManager; |
19
|
|
|
use FOS\ElasticaBundle\Index\MappingBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Container; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create command test |
24
|
|
|
* |
25
|
|
|
* @author Oleg Andreyev <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class CreateCommandTest extends \PHPUnit_Framework_TestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var IndexManager|\PHPUnit_Framework_MockObject_MockObject |
31
|
|
|
*/ |
32
|
|
|
private $indexManager; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var MappingBuilder|\PHPUnit_Framework_MockObject_MockObject |
36
|
|
|
*/ |
37
|
|
|
private $mappingBuilder; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ConfigManager|\PHPUnit_Framework_MockObject_MockObject |
41
|
|
|
*/ |
42
|
|
|
private $configManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var AliasProcessor|\PHPUnit_Framework_MockObject_MockObject |
46
|
|
|
*/ |
47
|
|
|
private $aliasProcessor; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var CreateCommand |
51
|
|
|
*/ |
52
|
|
|
private $command; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var IndexConfig |
56
|
|
|
*/ |
57
|
|
|
private $indexConfig; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var Index |
61
|
|
|
*/ |
62
|
|
|
private $index; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function setup() |
68
|
|
|
{ |
69
|
|
|
$container = new Container(); |
70
|
|
|
$this->indexManager = $this->getMockBuilder('\FOS\ElasticaBundle\Index\IndexManager') |
71
|
|
|
->disableOriginalConstructor() |
72
|
|
|
->getMock(); |
73
|
|
|
$this->mappingBuilder = $this->getMockBuilder('FOS\ElasticaBundle\Index\MappingBuilder') |
74
|
|
|
->disableOriginalConstructor() |
75
|
|
|
->getMock(); |
76
|
|
|
$this->configManager = $this->getMockBuilder('FOS\ElasticaBundle\Configuration\ConfigManager') |
77
|
|
|
->disableOriginalConstructor() |
78
|
|
|
->getMock(); |
79
|
|
|
$this->aliasProcessor = $this->getMockBuilder('FOS\ElasticaBundle\Index\AliasProcessor') |
80
|
|
|
->disableOriginalConstructor() |
81
|
|
|
->getMock(); |
82
|
|
|
$this->indexConfig = $this->getMockBuilder('\FOS\ElasticaBundle\Configuration\IndexConfig') |
83
|
|
|
->disableOriginalConstructor() |
84
|
|
|
->getMock(); |
85
|
|
|
$this->index = $this->getMockBuilder('\FOS\ElasticaBundle\Elastica\Index') |
86
|
|
|
->disableOriginalConstructor() |
87
|
|
|
->getMock(); |
88
|
|
|
|
89
|
|
|
$container->set('fos_elastica.index_manager', $this->indexManager); |
90
|
|
|
$container->set('fos_elastica.mapping_builder', $this->mappingBuilder); |
91
|
|
|
$container->set('fos_elastica.config_manager', $this->configManager); |
92
|
|
|
$container->set('fos_elastica.alias_processor', $this->aliasProcessor); |
93
|
|
|
|
94
|
|
|
$this->command = new CreateCommand(); |
95
|
|
|
$this->command->setContainer($container); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Test execute with index provided and with alias |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
View Code Duplication |
public function testExecuteWithIndexProvidedAndWithAlias() |
104
|
|
|
{ |
105
|
|
|
$input = $this->getMockForAbstractClass('\Symfony\Component\Console\Input\InputInterface'); |
106
|
|
|
$output = $this->getMockForAbstractClass('\Symfony\Component\Console\Output\OutputInterface'); |
107
|
|
|
|
108
|
|
|
$indexName = 'foo'; |
109
|
|
|
$mapping = ['mapping']; |
110
|
|
|
|
111
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
112
|
|
|
$output->expects($this->once())->method('writeln'); |
113
|
|
|
$this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig); |
114
|
|
|
$this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index); |
115
|
|
|
$this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(true); |
|
|
|
|
116
|
|
|
$this->aliasProcessor->expects($this->once())->method('setRootName')->with($this->indexConfig, $this->index); |
117
|
|
|
$this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping); |
118
|
|
|
$this->index->expects($this->once())->method('create')->with(['mapping'], false); |
|
|
|
|
119
|
|
|
|
120
|
|
|
$this->command->run($input, $output); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Test execute with index provided and without alias |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
public function testExecuteWithIndexProvidedAndWithoutAlias() |
129
|
|
|
{ |
130
|
|
|
$input = $this->getMockForAbstractClass('\Symfony\Component\Console\Input\InputInterface'); |
131
|
|
|
$output = $this->getMockForAbstractClass('\Symfony\Component\Console\Output\OutputInterface'); |
132
|
|
|
|
133
|
|
|
$indexName = 'foo'; |
134
|
|
|
$mapping = ['mapping']; |
135
|
|
|
|
136
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
137
|
|
|
$output->expects($this->once())->method('writeln'); |
138
|
|
|
$this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig); |
139
|
|
|
$this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index); |
140
|
|
|
$this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(false); |
|
|
|
|
141
|
|
|
$this->aliasProcessor->expects($this->never())->method('setRootName'); |
142
|
|
|
$this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping); |
143
|
|
|
$this->index->expects($this->once())->method('create')->with(['mapping'], false); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$this->command->run($input, $output); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testExecuteAllIndices() |
149
|
|
|
{ |
150
|
|
|
$input = $this->getMockForAbstractClass('\Symfony\Component\Console\Input\InputInterface'); |
151
|
|
|
$output = $this->getMockForAbstractClass('\Symfony\Component\Console\Output\OutputInterface'); |
152
|
|
|
$indexConfig1 = clone $this->indexConfig; |
153
|
|
|
$indexConfig2 = clone $this->indexConfig; |
154
|
|
|
$index1 = clone $this->index; |
155
|
|
|
$index2 = clone $this->index; |
156
|
|
|
|
157
|
|
|
$indexName = null; |
158
|
|
|
$indices = ['foo', 'bar']; |
159
|
|
|
$mapping = ['mapping']; |
160
|
|
|
|
161
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
162
|
|
|
$this->indexManager->expects($this->once())->method('getAllIndexes')->willReturn(array_flip($indices)); |
163
|
|
|
$output->expects($this->exactly(2))->method('writeln'); |
164
|
|
|
|
165
|
|
|
$this->configManager->expects($this->exactly(2))->method('getIndexConfiguration') |
166
|
|
|
->withConsecutive(['foo'], ['bar']) |
167
|
|
|
->willReturnOnConsecutiveCalls($indexConfig1, $indexConfig2); |
168
|
|
|
|
169
|
|
|
$this->indexManager->expects($this->exactly(2))->method('getIndex') |
170
|
|
|
->withConsecutive(['foo'], ['bar']) |
171
|
|
|
->willReturnOnConsecutiveCalls($index1, $index2); |
172
|
|
|
|
173
|
|
|
$indexConfig1->expects($this->once())->method('isUseAlias')->willReturn(false); |
|
|
|
|
174
|
|
|
$indexConfig2->expects($this->once())->method('isUseAlias')->willReturn(false); |
|
|
|
|
175
|
|
|
|
176
|
|
|
$this->aliasProcessor->expects($this->never())->method('setRootName'); |
177
|
|
|
|
178
|
|
|
$this->mappingBuilder->expects($this->exactly(2))->method('buildIndexMapping') |
179
|
|
|
->withConsecutive([$indexConfig1], [$indexConfig2]) |
180
|
|
|
->willReturn($mapping); |
181
|
|
|
|
182
|
|
|
$index1->expects($this->once())->method('create')->with(['mapping'], false); |
|
|
|
|
183
|
|
|
$index2->expects($this->once())->method('create')->with(['mapping'], false); |
|
|
|
|
184
|
|
|
|
185
|
|
|
$this->command->run($input, $output); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.