1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FOS\ElasticaBundle\Tests\Command; |
4
|
|
|
|
5
|
|
|
use FOS\ElasticaBundle\Command\ResetCommand; |
6
|
|
|
use FOS\ElasticaBundle\Index\IndexManager; |
7
|
|
|
use FOS\ElasticaBundle\Index\Resetter; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
10
|
|
|
use Symfony\Component\DependencyInjection\Container; |
11
|
|
|
|
12
|
|
|
class ResetCommandTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ResetCommand |
16
|
|
|
*/ |
17
|
|
|
private $command; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|Resetter |
21
|
|
|
*/ |
22
|
|
|
private $resetter; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|IndexManager |
26
|
|
|
*/ |
27
|
|
|
private $indexManager; |
28
|
|
|
|
29
|
|
|
public function setup() |
30
|
|
|
{ |
31
|
|
|
$container = new Container(); |
32
|
|
|
|
33
|
|
|
$this->resetter = $this->getMockBuilder('\FOS\ElasticaBundle\Resetter') |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->setMethods(array('resetIndex', 'resetIndexType', 'resetAllTemplates', 'resetTemplate')) |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$container->set('fos_elastica.resetter', $this->resetter); |
39
|
|
|
|
40
|
|
|
$this->indexManager = $this->getMockBuilder('\FOS\ElasticaBundle\IndexManager') |
41
|
|
|
->disableOriginalConstructor() |
42
|
|
|
->setMethods(array('getAllIndexes')) |
43
|
|
|
->getMock(); |
44
|
|
|
|
45
|
|
|
$container->set('fos_elastica.index_manager', $this->indexManager); |
46
|
|
|
|
47
|
|
|
$this->command = new ResetCommand(); |
|
|
|
|
48
|
|
|
$this->command->setContainer($container); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testResetAllIndexes() |
52
|
|
|
{ |
53
|
|
|
$this->indexManager->expects($this->any()) |
54
|
|
|
->method('getAllIndexes') |
55
|
|
|
->will($this->returnValue(array('index1' => true, 'index2' => true))); |
56
|
|
|
|
57
|
|
|
$this->resetter->expects($this->at(0)) |
58
|
|
|
->method('resetAllTemplates'); |
59
|
|
|
|
60
|
|
|
$this->resetter->expects($this->at(1)) |
61
|
|
|
->method('resetIndex') |
62
|
|
|
->with($this->equalTo('index1')); |
63
|
|
|
|
64
|
|
|
$this->resetter->expects($this->at(2)) |
65
|
|
|
->method('resetIndex') |
66
|
|
|
->with($this->equalTo('index2')); |
67
|
|
|
|
68
|
|
|
$this->command->run( |
69
|
|
|
new ArrayInput(array()), |
70
|
|
|
new NullOutput() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testResetIndex() |
75
|
|
|
{ |
76
|
|
|
$this->indexManager->expects($this->never()) |
77
|
|
|
->method('getAllIndexes'); |
78
|
|
|
|
79
|
|
|
$this->resetter->expects($this->at(0)) |
80
|
|
|
->method('resetAllTemplates'); |
81
|
|
|
|
82
|
|
|
$this->resetter->expects($this->at(1)) |
83
|
|
|
->method('resetIndex') |
84
|
|
|
->with($this->equalTo('index1')); |
85
|
|
|
|
86
|
|
|
$this->command->run( |
87
|
|
|
new ArrayInput(array('--index' => 'index1')), |
88
|
|
|
new NullOutput() |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testResetIndexType() |
93
|
|
|
{ |
94
|
|
|
$this->indexManager->expects($this->never()) |
95
|
|
|
->method('getAllIndexes'); |
96
|
|
|
|
97
|
|
|
$this->resetter->expects($this->never()) |
98
|
|
|
->method('resetIndex'); |
99
|
|
|
|
100
|
|
|
$this->resetter->expects($this->at(0)) |
101
|
|
|
->method('resetAllTemplates'); |
102
|
|
|
|
103
|
|
|
$this->resetter->expects($this->at(1)) |
104
|
|
|
->method('resetIndexType') |
105
|
|
|
->with($this->equalTo('index1'), $this->equalTo('type1')); |
106
|
|
|
|
107
|
|
|
$this->command->run( |
108
|
|
|
new ArrayInput(array('--index' => 'index1', '--type' => 'type1')), |
109
|
|
|
new NullOutput() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testResetAllIndexTemplates() |
114
|
|
|
{ |
115
|
|
|
$this->resetter->expects($this->once()) |
116
|
|
|
->method('resetAllTemplates') |
117
|
|
|
->with(false) |
118
|
|
|
; |
119
|
|
|
|
120
|
|
|
$this->resetter->expects($this->never()) |
121
|
|
|
->method('resetIndex'); |
122
|
|
|
|
123
|
|
|
$this->command->run( |
124
|
|
|
new ArrayInput(array('--index-template' => null)), |
125
|
|
|
new NullOutput() |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
public function testResetAndDeleteAllIndexTemplates() |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$this->resetter->expects($this->once()) |
132
|
|
|
->method('resetAllTemplates') |
133
|
|
|
->with(true) |
134
|
|
|
; |
135
|
|
|
|
136
|
|
|
$this->resetter->expects($this->never()) |
137
|
|
|
->method('resetIndex'); |
138
|
|
|
|
139
|
|
|
$this->command->run( |
140
|
|
|
new ArrayInput(array('--index-template' => null, '--delete-template-indexes' => null)), |
141
|
|
|
new NullOutput() |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testResetOneIndexTemplate() |
146
|
|
|
{ |
147
|
|
|
$this->resetter->expects($this->once()) |
148
|
|
|
->method('resetTemplate') |
149
|
|
|
->with('template name', false) |
150
|
|
|
; |
151
|
|
|
|
152
|
|
|
$this->resetter->expects($this->never()) |
153
|
|
|
->method('resetIndex'); |
154
|
|
|
|
155
|
|
|
$this->command->run( |
156
|
|
|
new ArrayInput(array('--index-template' => 'template name')), |
157
|
|
|
new NullOutput() |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
View Code Duplication |
public function testResetAndDeleteOneIndexTemplate() |
|
|
|
|
162
|
|
|
{ |
163
|
|
|
$this->resetter->expects($this->once()) |
164
|
|
|
->method('resetTemplate') |
165
|
|
|
->with('template name', true) |
166
|
|
|
; |
167
|
|
|
|
168
|
|
|
$this->resetter->expects($this->never()) |
169
|
|
|
->method('resetIndex'); |
170
|
|
|
|
171
|
|
|
$this->command->run( |
172
|
|
|
new ArrayInput(array('--index-template' => 'template name', '--delete-template-indexes' => null)), |
173
|
|
|
new NullOutput() |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @expectedException \InvalidArgumentException |
179
|
|
|
*/ |
180
|
|
|
public function testThrowExceptionWhenIndexAndIndexTemplateProvidedInSameTime() |
181
|
|
|
{ |
182
|
|
|
$this->command->run( |
183
|
|
|
new ArrayInput(array('--index-template' => null, '--index' => 'some template')), |
184
|
|
|
new NullOutput() |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..