diff --git a/MappingRegistry.php b/MappingRegistry.php deleted file mode 100644 index 3573e9f..0000000 --- a/MappingRegistry.php +++ /dev/null @@ -1,60 +0,0 @@ - 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]); - } -} diff --git a/Tests/MappingRegistryTest.php b/Tests/MappingRegistryTest.php deleted file mode 100644 index 197eb29..0000000 --- a/Tests/MappingRegistryTest.php +++ /dev/null @@ -1,91 +0,0 @@ -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; - } -}