|
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\ResetCommand; |
|
15
|
|
|
use FOS\ElasticaBundle\Index\IndexManager; |
|
16
|
|
|
use FOS\ElasticaBundle\Index\Resetter; |
|
17
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
18
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
19
|
|
|
|
|
20
|
|
|
class ResetCommandTest extends \PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var ResetCommand |
|
24
|
|
|
*/ |
|
25
|
|
|
private $command; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Resetter|\PHPUnit_Framework_MockObject_MockObject |
|
29
|
|
|
*/ |
|
30
|
|
|
private $resetter; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var IndexManager|\PHPUnit_Framework_MockObject_MockObject |
|
34
|
|
|
*/ |
|
35
|
|
|
private $indexManager; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->resetter = $this->getMockBuilder(Resetter::class) |
|
40
|
|
|
->disableOriginalConstructor() |
|
41
|
|
|
->setMethods(['resetIndex', 'resetIndexType']) |
|
42
|
|
|
->getMock(); |
|
43
|
|
|
|
|
44
|
|
|
$this->indexManager = $this->getMockBuilder(IndexManager::class) |
|
45
|
|
|
->disableOriginalConstructor() |
|
46
|
|
|
->setMethods(['getAllIndexes']) |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
|
|
49
|
|
|
$this->command = new ResetCommand($this->indexManager, $this->resetter); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testResetAllIndexes() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->indexManager->expects($this->any()) |
|
55
|
|
|
->method('getAllIndexes') |
|
56
|
|
|
->will($this->returnValue(['index1' => true, 'index2' => true])); |
|
57
|
|
|
|
|
58
|
|
|
$this->resetter->expects($this->at(0)) |
|
59
|
|
|
->method('resetIndex') |
|
60
|
|
|
->with($this->equalTo('index1')); |
|
61
|
|
|
|
|
62
|
|
|
$this->resetter->expects($this->at(1)) |
|
63
|
|
|
->method('resetIndex') |
|
64
|
|
|
->with($this->equalTo('index2')); |
|
65
|
|
|
|
|
66
|
|
|
$this->command->run( |
|
67
|
|
|
new ArrayInput([]), |
|
68
|
|
|
new NullOutput() |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testResetIndex() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->indexManager->expects($this->never()) |
|
75
|
|
|
->method('getAllIndexes'); |
|
76
|
|
|
|
|
77
|
|
|
$this->resetter->expects($this->at(0)) |
|
78
|
|
|
->method('resetIndex') |
|
79
|
|
|
->with($this->equalTo('index1')); |
|
80
|
|
|
|
|
81
|
|
|
$this->command->run( |
|
82
|
|
|
new ArrayInput(['--index' => 'index1']), |
|
83
|
|
|
new NullOutput() |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testResetIndexType() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->indexManager->expects($this->never()) |
|
90
|
|
|
->method('getAllIndexes'); |
|
91
|
|
|
|
|
92
|
|
|
$this->resetter->expects($this->never()) |
|
93
|
|
|
->method('resetIndex'); |
|
94
|
|
|
|
|
95
|
|
|
$this->resetter->expects($this->at(0)) |
|
96
|
|
|
->method('resetIndexType') |
|
97
|
|
|
->with($this->equalTo('index1'), $this->equalTo('type1')); |
|
98
|
|
|
|
|
99
|
|
|
$this->command->run( |
|
100
|
|
|
new ArrayInput(['--index' => 'index1', '--type' => 'type1']), |
|
101
|
|
|
new NullOutput() |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|