Adding tests

This commit is contained in:
Lea Haensenberger 2013-12-16 12:06:53 +01:00
parent 05ee300ddb
commit e906d780ad

View file

@ -4,6 +4,9 @@ namespace FOS\ElasticaBundle\Tests\Command;
use FOS\ElasticaBundle\Command\ResetCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\DependencyInjection\Container;
class ResetCommandTest extends \PHPUnit_Framework_TestCase
{
@ -27,6 +30,8 @@ class ResetCommandTest extends \PHPUnit_Framework_TestCase
->setMethods(array('getAllIndexes'))
->getMock();
$container->set('fos_elastica.index_manager', $this->indexManager);
$this->command = new ResetCommand();
$this->command->setContainer($container);
}
@ -35,13 +40,13 @@ class ResetCommandTest extends \PHPUnit_Framework_TestCase
{
$this->indexManager->expects($this->any())
->method('getAllIndexes')
->will($this->returnValue(array('index1', 'index2')));
->will($this->returnValue(array('index1' => true, 'index2' => true)));
$this->resetter->expects($this->at(1))
$this->resetter->expects($this->at(0))
->method('resetIndex')
->with($this->equalTo('index1'));
$this->resetter->expects($this->at(2))
$this->resetter->expects($this->at(1))
->method('resetIndex')
->with($this->equalTo('index2'));
@ -50,4 +55,37 @@ class ResetCommandTest extends \PHPUnit_Framework_TestCase
new NullOutput()
);
}
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()
);
}
}