Remove obsolete MappingRegistry class

This commit is contained in:
Jeremy Mikola 2012-03-09 12:43:57 -05:00
parent b360a36737
commit 2d2e209373
2 changed files with 0 additions and 151 deletions

View file

@ -1,60 +0,0 @@
<?php
namespace FOQ\ElasticaBundle;
use Elastica_Type;
use InvalidArgumentException;
/**
* Stores the configured mappings for all types
* Responsible for applying configured mappings to elastica types
*/
class MappingRegistry
{
/**
* Configured mappings. See http://www.elasticsearch.org/guide/reference/mapping/
* array(
* "index_name/type_name" => array(type_object, mapping_array)
* )
*
* @var array
*/
protected $mappings = null;
/**
* Instanciates a new MappingSetter
*
* @param array mappings
*/
public function __construct($mappings)
{
$this->mappings = $mappings;
}
/**
* Apply mappings to all elastica types
**/
public function applyMappings()
{
foreach ($this->mappings as $pair) {
list($type, $mappings) = $pair;
$type->setMapping($mappings);
}
}
/**
* Gets the type mapping field names
*
* @param Elastica_Type $type
* @return array list of fields names
*/
public function getTypeFieldNames(Elastica_Type $type)
{
$key = sprintf('%s/%s', $type->getIndex()->getName(), $type->getType());
if (!isset($this->mappings[$key])) {
throw new InvalidArgumentException(sprintf('This type is not registered: "%s".', $key));
}
return array_keys($this->mappings[$key][1]);
}
}

View file

@ -1,91 +0,0 @@
<?php
namespace FOQ\ElasticaBundle\Tests\MappingRegistry;
use FOQ\ElasticaBundle\MappingRegistry;
use Elastica_Type;
use Elastica_Index;
class MappingRegistryTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!class_exists('Elastica_Type') || !class_exists('Elastica_Index')) {
$this->markTestSkipped('The Elastica library classes are not available');
}
}
public function testThatCanApplyMappings()
{
$typeMock = $this->getMockBuilder('Elastica_Type')
->disableOriginalConstructor()
->getMock();
$typeMock->expects($this->once())
->method('setMapping')
->with($this->equalTo(array('mappingArray')));
$mapping = new MappingRegistry(array(
'index/type' => array($typeMock, array('mappingArray'))
));
$mapping->applyMappings();
}
/**
* @dataProvider invalidTypesParametersProvider
* @expectedException InvalidArgumentException
*/
public function testThatCannotGetTypeFieldForTypeWhichNotExists($indexName, $typeName)
{
$type = $this->getTypeMock('index', 'type');
$mapping = new MappingRegistry(array(
'index/type' => array($type, array('mappingArray'))
));
$mapping->getTypeFieldNames($this->getTypeMock($indexName, $typeName));
}
public function testThatCanGetTypeField()
{
$type = $this->getTypeMock('index', 'type');
$mapping = new MappingRegistry(array(
'index/type' => array($type, array('mappingArray'))
));
$mapping->getTypeFieldNames($this->getTypeMock('index', 'type'));
}
public static function invalidTypesParametersProvider()
{
return array(
array('index1', 'type'),
array('index', 'type2')
);
}
private function getTypeMock($indexName, $typeName)
{
$typeMock = $this->getMockBuilder('Elastica_Type')
->disableOriginalConstructor()
->getMock();
$indexMock = $this->getMockBuilder('Elastica_Index')
->disableOriginalConstructor()
->getMock();
$indexMock->expects($this->any())
->method('getName')
->will($this->returnValue($indexName));
$typeMock->expects($this->any())
->method('getIndex')
->will($this->returnValue($indexMock));
$typeMock->expects($this->any())
->method('getType')
->will($this->returnValue($typeName));
return $typeMock;
}
}