2013-12-16 11:58:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FOS\ElasticaBundle\Tests\Command;
|
|
|
|
|
|
|
|
use FOS\ElasticaBundle\Command\ResetCommand;
|
2013-12-16 12:06:53 +01:00
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
|
use Symfony\Component\Console\Output\NullOutput;
|
|
|
|
use Symfony\Component\DependencyInjection\Container;
|
2013-12-16 11:58:58 +01:00
|
|
|
|
|
|
|
class ResetCommandTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2015-03-13 09:10:24 +01:00
|
|
|
private $command;
|
2013-12-16 11:58:58 +01:00
|
|
|
private $resetter;
|
|
|
|
private $indexManager;
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
{
|
|
|
|
$container = new Container();
|
|
|
|
|
|
|
|
$this->resetter = $this->getMockBuilder('\FOS\ElasticaBundle\Resetter')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(array('resetIndex', 'resetIndexType'))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$container->set('fos_elastica.resetter', $this->resetter);
|
|
|
|
|
|
|
|
$this->indexManager = $this->getMockBuilder('\FOS\ElasticaBundle\IndexManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(array('getAllIndexes'))
|
|
|
|
->getMock();
|
|
|
|
|
2013-12-16 12:06:53 +01:00
|
|
|
$container->set('fos_elastica.index_manager', $this->indexManager);
|
|
|
|
|
2013-12-16 11:58:58 +01:00
|
|
|
$this->command = new ResetCommand();
|
|
|
|
$this->command->setContainer($container);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResetAllIndexes()
|
|
|
|
{
|
|
|
|
$this->indexManager->expects($this->any())
|
|
|
|
->method('getAllIndexes')
|
2013-12-16 12:06:53 +01:00
|
|
|
->will($this->returnValue(array('index1' => true, 'index2' => true)));
|
2013-12-16 11:58:58 +01:00
|
|
|
|
2013-12-16 12:06:53 +01:00
|
|
|
$this->resetter->expects($this->at(0))
|
2013-12-16 11:58:58 +01:00
|
|
|
->method('resetIndex')
|
|
|
|
->with($this->equalTo('index1'));
|
|
|
|
|
2013-12-16 12:06:53 +01:00
|
|
|
$this->resetter->expects($this->at(1))
|
2013-12-16 11:58:58 +01:00
|
|
|
->method('resetIndex')
|
|
|
|
->with($this->equalTo('index2'));
|
|
|
|
|
|
|
|
$this->command->run(
|
|
|
|
new ArrayInput(array()),
|
|
|
|
new NullOutput()
|
|
|
|
);
|
|
|
|
}
|
2013-12-16 12:06:53 +01:00
|
|
|
|
|
|
|
public function testResetIndex()
|
|
|
|
{
|
|
|
|
$this->indexManager->expects($this->never())
|
|
|
|
->method('getAllIndexes');
|
|
|
|
|
|
|
|
$this->resetter->expects($this->at(0))
|
|
|
|
->method('resetIndex')
|
|
|
|
->with($this->equalTo('index1'));
|
|
|
|
|
|
|
|
$this->command->run(
|
|
|
|
new ArrayInput(array('--index' => 'index1')),
|
|
|
|
new NullOutput()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResetIndexType()
|
|
|
|
{
|
|
|
|
$this->indexManager->expects($this->never())
|
|
|
|
->method('getAllIndexes');
|
|
|
|
|
|
|
|
$this->resetter->expects($this->never())
|
|
|
|
->method('resetIndex');
|
|
|
|
|
|
|
|
$this->resetter->expects($this->at(0))
|
|
|
|
->method('resetIndexType')
|
|
|
|
->with($this->equalTo('index1'), $this->equalTo('type1'));
|
|
|
|
|
|
|
|
$this->command->run(
|
|
|
|
new ArrayInput(array('--index' => 'index1', '--type' => 'type1')),
|
|
|
|
new NullOutput()
|
|
|
|
);
|
|
|
|
}
|
2015-03-12 11:20:00 +01:00
|
|
|
}
|