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