2011-07-07 22:42:03 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-02 06:28:38 +01:00
|
|
|
namespace FOQ\ElasticaBundle\Tests\Resetter;
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-02 06:28:38 +01:00
|
|
|
use FOQ\ElasticaBundle\Resetter;
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
class ResetterTest extends \PHPUnit_Framework_TestCase
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
private $indexConfigsByName;
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
public function setUp()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$this->indexConfigsByName = array(
|
|
|
|
'foo' => array(
|
|
|
|
'index' => $this->getMockElasticaIndex(),
|
|
|
|
'config' => array(
|
|
|
|
'mappings' => array(
|
2012-07-02 15:00:40 +02:00
|
|
|
'a' => array('properties' => array()),
|
|
|
|
'b' => array('properties' => array()),
|
2012-03-09 19:02:26 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'bar' => array(
|
|
|
|
'index' => $this->getMockElasticaIndex(),
|
|
|
|
'config' => array(
|
|
|
|
'mappings' => array(
|
2012-07-02 15:00:40 +02:00
|
|
|
'a' => array('properties' => array()),
|
|
|
|
'b' => array('properties' => array()),
|
2012-03-09 19:02:26 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
public function testResetAllIndexes()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$this->indexConfigsByName['foo']['index']->expects($this->once())
|
|
|
|
->method('create')
|
|
|
|
->with($this->indexConfigsByName['foo']['config'], true);
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
$this->indexConfigsByName['bar']['index']->expects($this->once())
|
|
|
|
->method('create')
|
|
|
|
->with($this->indexConfigsByName['bar']['config'], true);
|
|
|
|
|
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetAllIndexes();
|
|
|
|
}
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
public function testResetIndex()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$this->indexConfigsByName['foo']['index']->expects($this->once())
|
|
|
|
->method('create')
|
|
|
|
->with($this->indexConfigsByName['foo']['config'], true);
|
|
|
|
|
|
|
|
$this->indexConfigsByName['bar']['index']->expects($this->never())
|
|
|
|
->method('create');
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetIndex('foo');
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testResetIndexShouldThrowExceptionForInvalidIndex()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetIndex('baz');
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
public function testResetIndexType()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$type = $this->getMockElasticaType();
|
|
|
|
|
|
|
|
$this->indexConfigsByName['foo']['index']->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->with('a')
|
|
|
|
->will($this->returnValue($type));
|
|
|
|
|
|
|
|
$type->expects($this->once())
|
|
|
|
->method('delete');
|
|
|
|
|
|
|
|
$type->expects($this->once())
|
|
|
|
->method('setMapping')
|
2012-07-02 15:00:40 +02:00
|
|
|
->with($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
2012-03-09 19:02:26 +01:00
|
|
|
|
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetIndexType('foo', 'a');
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testResetIndexTypeShouldThrowExceptionForInvalidIndex()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2012-03-09 19:02:26 +01:00
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetIndexType('baz', 'a');
|
|
|
|
}
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testResetIndexTypeShouldThrowExceptionForInvalidType()
|
|
|
|
{
|
|
|
|
$resetter = new Resetter($this->indexConfigsByName);
|
|
|
|
$resetter->resetIndexType('foo', 'c');
|
|
|
|
}
|
2011-07-07 22:58:43 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
/**
|
|
|
|
* @return Elastica_Index
|
|
|
|
*/
|
|
|
|
private function getMockElasticaIndex()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Elastica_Index')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
2011-07-07 22:58:43 +02:00
|
|
|
|
2012-03-09 19:02:26 +01:00
|
|
|
/**
|
|
|
|
* @return Elastica_Type
|
|
|
|
*/
|
|
|
|
private function getMockElasticaType()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Elastica_Type')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
}
|