adding unit test for PopulateListener

This commit is contained in:
Oleg Andreyev 2015-01-04 13:34:59 +02:00
parent 303af508b2
commit afbe1e03a1
2 changed files with 58 additions and 4 deletions

View file

@ -46,10 +46,10 @@ class PopulateEvent extends Event
private $options;
/**
* @param string $index
* @param string $type
* @param boolean $reset
* @param array $options
* @param string $index
* @param string|null $type
* @param boolean $reset
* @param array $options
*/
public function __construct($index, $type, $reset, $options)
{

View file

@ -0,0 +1,54 @@
<?php
namespace FOS\ElasticaBundle\Tests\EventListener;
use FOS\ElasticaBundle\Event\PopulateEvent;
use FOS\ElasticaBundle\EventListener\PopulateListener;
use PHPUnit_Framework_MockObject_MockObject;
class PopulateListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PHPUnit_Framework_MockObject_MockObject
*/
private $resetter;
/**
* @var PopulateListener
*/
private $listener;
protected function setUp()
{
$this->resetter = $this->getMockBuilder('FOS\ElasticaBundle\Index\Resetter')
->disableOriginalConstructor()
->getMock();
$this->listener = new PopulateListener($this->resetter);
}
public function testPostIndexPopulate()
{
$this->resetter->expects($this->once())->method('postPopulate')->with('indexName');
$this->listener->postIndexPopulate(new PopulateEvent('indexName', null, true, array()));
}
public function testPreIndexPopulateWhenNoResetRequired()
{
$this->resetter->expects($this->never())->method('resetIndex');
$this->resetter->expects($this->never())->method('resetIndexType');
$this->listener->preIndexPopulate(new PopulateEvent('indexName', null, false, array()));
}
public function testPreIndexPopulateWhenResetIsRequiredAndNoTypeIsSpecified()
{
$this->resetter->expects($this->once())->method('resetIndex')->with('indexName');
$this->listener->preIndexPopulate(new PopulateEvent('indexName', null, true, array()));
}
public function testPreIndexPopulateWhenResetIsRequiredAndTypeIsSpecified()
{
$this->resetter->expects($this->once())->method('resetIndexType')->with('indexName', 'indexType');
$this->listener->preIndexPopulate(new PopulateEvent('indexName', 'indexType', true, array()));
}
}