public function testRemoveTypeByIndexMultiple() { $this->assertSame(0, $this->index->countTypes()); $this->index->addType($this->type); $this->index->addType($this->type); $this->index->addType($this->type); $this->assertSame(3, $this->index->countTypes()); $this->index->removeTypeByIndex(0); $this->index->removeTypeByIndex(1); $this->assertSame(1, $this->index->countTypes()); }
/** * Get mappings for all indices * * @param string $host * @param int $port * @return Mappings * @throws \Exception * @author Daniel Wendlandt */ public function getAllMappings($host, $port = 9200) { $this->checkServerInfo($host, $port); $request = $this->requestFactory->create('Index\\GetMappingRequest', $this->serverInfo->version, null, null, $this->getSerializer()); $client = $this->getClient($host, $port); $response = $client->send($request); $mappings = new Mappings(); foreach ($response->getData() as $indexName => $typeMappings) { $index = new Mappings\Index(); $index->setName($indexName); foreach ($typeMappings['mappings'] as $typeName => $schema) { $type = new Mappings\Type(); $type->setName($typeName); $type->setSchema($schema); $index->addType($type); } $mappings->addIndex($index); } return $mappings; }
public function testStoreMappings() { $path = '/tmp/test-path'; $mappings = new Mappings(); $type1 = new Mappings\Type(); $type1->setName('type1'); $type1->setSchema(array('properties' => array())); $type2 = new Mappings\Type(); $type2->setName('type2'); $type2->setSchema(array('properties' => array())); $index1 = new Mappings\Index(); $index1->setName('index1'); $index1->addType($type1); $index1->addType($type2); $mappings->addIndex($index1); $folderPath = $path . DIRECTORY_SEPARATOR . FilesystemRepositoryInterface::DIR_SCHEMA . DIRECTORY_SEPARATOR . $index1->getName(); $schemaPath1 = $folderPath . DIRECTORY_SEPARATOR . $type1->getName() . FilesystemRepositoryInterface::FILE_EXTENSION; $schemaPath2 = $folderPath . DIRECTORY_SEPARATOR . $type2->getName() . FilesystemRepositoryInterface::FILE_EXTENSION; $this->filesystem->expects($this->once())->method('mkdir')->with($folderPath); $this->filesystem->expects($this->exactly(2))->method('dumpFile')->withConsecutive(array($schemaPath1, json_encode($type1->getSchema())), array($schemaPath2, json_encode($type2->getSchema()))); $createdFiles = $this->filesystemRepository->storeMappings($path, $mappings); $this->assertSame(2, $createdFiles); }