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
|
|
|
use FOQ\ElasticaBundle\IndexManager;
|
|
|
|
use Elastica_Exception_Response;
|
|
|
|
use Elastica_Response;
|
|
|
|
|
|
|
|
class Index
|
|
|
|
{
|
|
|
|
public $deleted = false;
|
|
|
|
public $created = false;
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$this->deleted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$this->created = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewIndex
|
|
|
|
{
|
|
|
|
public $deleted = false;
|
|
|
|
public $created = false;
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$jsonResponse = json_encode(array('index' => 'is_new'));
|
|
|
|
|
|
|
|
throw new Elastica_Exception_Response(new Elastica_Response($jsonResponse));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$this->created = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-02 06:28:38 +01:00
|
|
|
class ResetterTest extends \PHPUnit_Framework_TestCase
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2011-07-28 22:37:54 +02:00
|
|
|
if (!class_exists('Elastica_Exception_Response') || !class_exists('Elastica_Response')) {
|
2011-07-07 23:42:03 +02:00
|
|
|
$this->markTestSkipped('The Elastica library classes are not available');
|
2011-07-07 22:58:43 +02:00
|
|
|
}
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
|
|
|
|
2011-11-12 21:05:54 +01:00
|
|
|
public function testThatResetMethodRecreateAllIndexes()
|
2011-07-07 22:42:03 +02:00
|
|
|
{
|
2011-11-12 21:05:54 +01:00
|
|
|
$indexConfig = array();
|
|
|
|
$indexConfig['index_1'] = array();
|
|
|
|
$indexConfig['index_1']['index'] = new Index();
|
|
|
|
$indexConfig['index_1']['config'] = array();
|
|
|
|
$indexConfig['index_2'] = array();
|
|
|
|
$indexConfig['index_2']['index'] = new Index();
|
|
|
|
$indexConfig['index_2']['config'] = array();
|
2011-07-07 22:42:03 +02:00
|
|
|
|
2011-07-07 22:58:43 +02:00
|
|
|
|
2012-03-02 06:28:38 +01:00
|
|
|
$resetter = new Resetter($indexConfig);
|
|
|
|
$resetter->reset();
|
2011-07-07 22:58:43 +02:00
|
|
|
|
2011-11-12 21:05:54 +01:00
|
|
|
$this->assertTrue($indexConfig['index_1']['index']->created);
|
|
|
|
$this->assertTrue($indexConfig['index_2']['index']->created);
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|
2011-07-07 22:58:43 +02:00
|
|
|
|
2011-07-07 22:42:03 +02:00
|
|
|
}
|