FOSElasticaBundle/Tests/ResetterTest.php

72 lines
1.6 KiB
PHP
Raw Normal View History

2011-07-07 22:42:03 +02:00
<?php
namespace FOQ\ElasticaBundle\Tests\Resetter;
2011-07-07 22:42:03 +02: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;
}
}
class ResetterTest extends \PHPUnit_Framework_TestCase
2011-07-07 22:42:03 +02:00
{
public function setUp()
{
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
}
public function testThatResetMethodRecreateAllIndexes()
2011-07-07 22:42:03 +02: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
$resetter = new Resetter($indexConfig);
$resetter->reset();
2011-07-07 22:58:43 +02: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
}