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
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Oleg Andreyev <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class CreateCommandTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var IndexManager|\PHPUnit_Framework_MockObject_MockObject |
32
|
|
|
*/ |
33
|
|
|
private $indexManager; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var MappingBuilder|\PHPUnit_Framework_MockObject_MockObject |
37
|
|
|
*/ |
38
|
|
|
private $mappingBuilder; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var ConfigManager|\PHPUnit_Framework_MockObject_MockObject |
42
|
|
|
*/ |
43
|
|
|
private $configManager; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var AliasProcessor|\PHPUnit_Framework_MockObject_MockObject |
47
|
|
|
*/ |
48
|
|
|
private $aliasProcessor; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var CreateCommand |
52
|
|
|
*/ |
53
|
|
|
private $command; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var IndexConfig|\PHPUnit_Framework_MockObject_MockObject |
57
|
|
|
*/ |
58
|
|
|
private $indexConfig; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Index|\PHPUnit_Framework_MockObject_MockObject |
62
|
|
|
*/ |
63
|
|
|
private $index; |
64
|
|
|
|
65
|
|
|
protected function setUp() |
66
|
|
|
{ |
67
|
|
|
$this->indexManager = $this->createMock(IndexManager::class); |
68
|
|
|
$this->mappingBuilder = $this->createMock(MappingBuilder::class); |
69
|
|
|
$this->configManager = $this->createMock(ConfigManager::class); |
70
|
|
|
$this->aliasProcessor = $this->createMock(AliasProcessor::class); |
71
|
|
|
$this->indexConfig = $this->createMock(IndexConfig::class); |
72
|
|
|
$this->index = $this->createMock(Index::class); |
73
|
|
|
|
74
|
|
|
$this->command = new CreateCommand( |
75
|
|
|
$this->indexManager, |
|
|
|
|
76
|
|
|
$this->mappingBuilder, |
|
|
|
|
77
|
|
|
$this->configManager, |
|
|
|
|
78
|
|
|
$this->aliasProcessor |
|
|
|
|
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testExecuteWithIndexProvidedAndWithAlias() |
83
|
|
|
{ |
84
|
|
|
$input = $this->createMock(InputInterface::class); |
85
|
|
|
$output = $this->createMock(OutputInterface::class); |
86
|
|
|
|
87
|
|
|
$indexName = 'foo'; |
88
|
|
|
$mapping = ['mapping']; |
89
|
|
|
|
90
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
91
|
|
|
$output->expects($this->once())->method('writeln'); |
92
|
|
|
$this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig); |
93
|
|
|
$this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index); |
94
|
|
|
$this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(true); |
95
|
|
|
$this->aliasProcessor->expects($this->once())->method('setRootName')->with($this->indexConfig, $this->index); |
96
|
|
|
$this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping); |
97
|
|
|
$this->index->expects($this->once())->method('create')->with(['mapping'], false); |
98
|
|
|
|
99
|
|
|
$this->command->run($input, $output); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public function testExecuteWithIndexProvidedAndWithoutAlias() |
103
|
|
|
{ |
104
|
|
|
$input = $this->createMock(InputInterface::class); |
105
|
|
|
$output = $this->createMock(OutputInterface::class); |
106
|
|
|
|
107
|
|
|
$indexName = 'foo'; |
108
|
|
|
$mapping = ['mapping']; |
109
|
|
|
|
110
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
111
|
|
|
$output->expects($this->once())->method('writeln'); |
112
|
|
|
$this->configManager->expects($this->once())->method('getIndexConfiguration')->with($indexName)->willReturn($this->indexConfig); |
113
|
|
|
$this->indexManager->expects($this->once())->method('getIndex')->with($indexName)->willReturn($this->index); |
114
|
|
|
$this->indexConfig->expects($this->once())->method('isUseAlias')->willReturn(false); |
115
|
|
|
$this->aliasProcessor->expects($this->never())->method('setRootName'); |
116
|
|
|
$this->mappingBuilder->expects($this->once())->method('buildIndexMapping')->with($this->indexConfig)->willReturn($mapping); |
117
|
|
|
$this->index->expects($this->once())->method('create')->with(['mapping'], false); |
118
|
|
|
|
119
|
|
|
$this->command->run($input, $output); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testExecuteAllIndices() |
123
|
|
|
{ |
124
|
|
|
$input = $this->createMock(InputInterface::class); |
125
|
|
|
$output = $this->createMock(OutputInterface::class); |
126
|
|
|
$indexConfig1 = clone $this->indexConfig; |
127
|
|
|
$indexConfig2 = clone $this->indexConfig; |
128
|
|
|
$index1 = clone $this->index; |
129
|
|
|
$index2 = clone $this->index; |
130
|
|
|
|
131
|
|
|
$indexName = null; |
132
|
|
|
$indices = ['foo', 'bar']; |
133
|
|
|
$mapping = ['mapping']; |
134
|
|
|
|
135
|
|
|
$input->expects($this->once())->method('getOption')->with('index')->willReturn($indexName); |
136
|
|
|
$this->indexManager->expects($this->once())->method('getAllIndexes')->willReturn(array_flip($indices)); |
137
|
|
|
$output->expects($this->exactly(2))->method('writeln'); |
138
|
|
|
|
139
|
|
|
$this->configManager->expects($this->exactly(2))->method('getIndexConfiguration') |
140
|
|
|
->withConsecutive(['foo'], ['bar']) |
141
|
|
|
->willReturnOnConsecutiveCalls($indexConfig1, $indexConfig2); |
142
|
|
|
|
143
|
|
|
$this->indexManager->expects($this->exactly(2))->method('getIndex') |
144
|
|
|
->withConsecutive(['foo'], ['bar']) |
145
|
|
|
->willReturnOnConsecutiveCalls($index1, $index2); |
146
|
|
|
|
147
|
|
|
$indexConfig1->expects($this->once())->method('isUseAlias')->willReturn(false); |
148
|
|
|
$indexConfig2->expects($this->once())->method('isUseAlias')->willReturn(false); |
149
|
|
|
|
150
|
|
|
$this->aliasProcessor->expects($this->never())->method('setRootName'); |
151
|
|
|
|
152
|
|
|
$this->mappingBuilder->expects($this->exactly(2))->method('buildIndexMapping') |
153
|
|
|
->withConsecutive([$indexConfig1], [$indexConfig2]) |
154
|
|
|
->willReturn($mapping); |
155
|
|
|
|
156
|
|
|
$index1->expects($this->once())->method('create')->with(['mapping'], false); |
157
|
|
|
$index2->expects($this->once())->method('create')->with(['mapping'], false); |
158
|
|
|
|
159
|
|
|
$this->command->run($input, $output); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: