public function testDeleteDocument() { $this->createIndex(); $data = array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $id = $this->createDocument(self::TYPE, $data); $this->refreshIndex(); $deleteDocumentRequest = new DeleteDocumentRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $deleteDocumentRequest->setId($id); /** @var DeleteDocumentResponse $response */ $response = $this->getClient()->send($deleteDocumentRequest); $this->assertTrue($response->found()); $this->assertSame($id, $response->getId()); $this->assertSame(ES_INDEX, $response->getIndex()); $this->assertSame(self::TYPE, $response->getType()); $this->assertGreaterThan(1, $response->getVersion()); $getDocumentRequest = new GetDocumentRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $getDocumentRequest->setId($id); try { $this->getClient()->send($getDocumentRequest); } catch (ClientException $exception) { $this->assertSame(404, $exception->getCode()); $this->assertContains('Client error:', $exception->getMessage()); return; } $this->fail(); }
public function testGetDocumentMissingDoc() { $this->createIndex(); $data = array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $this->createDocument(self::TYPE, $data); $this->refreshIndex(); $getDocumentRequest = new GetDocumentRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $getDocumentRequest->setId('notExisting'); try { $this->getClient()->send($getDocumentRequest); } catch (ClientException $exception) { $this->assertSame(404, $exception->getCode()); $this->assertContains('Client error:', $exception->getMessage()); return; } $this->fail(); }
public function testCreateResponse() { $rawData = 'raw data for testing'; $response = $this->request->createResponse($rawData, $this->serializer); $this->assertInstanceOf(self::RESPONSE_CLASS, $response); }
/** * Gets the source of a single document * * @param string $index * @param string $type * @param string $id * @return array|object * @throws \Elastification\Client\Exception\RequestException * @throws \Elastification\Client\Exception\ResponseException */ protected function getDocument($index, $type, $id) { $getDocumentRequest = new GetDocumentRequest($index, $type, $this->serializer); $getDocumentRequest->setId($id); /** @var DocumentResponse $response */ $response = $this->client->send($getDocumentRequest); return $response->getSource(); }
public function testBulkDeleteFirstExisting() { $this->createIndex(); $doc1 = array('name' => 'test1' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)); $bulkCreateRequest = new BulkCreateRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $bulkCreateRequest->addDocument($doc1, 'doc1'); $bulkDeleteRequest = new BulkDeleteRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $bulkDeleteRequest->add(array('doc1', 'doc2', 'doc3')); /** @var BulkResponse $response */ $response = $this->getClient()->send($bulkCreateRequest); $this->assertGreaterThanOrEqual(0, $response->took()); $this->assertFalse($response->errors()); $response = $this->getClient()->send($bulkDeleteRequest); $this->assertGreaterThanOrEqual(0, $response->took()); $this->assertFalse($response->errors()); $items = $response->getItems(); $this->assertTrue(is_array($items)); $this->assertCount(3, $items); foreach ($items as $key => $item) { $this->assertArrayHasKey(AbstractBulkDeleteRequest::BULK_ACTION, $item); $this->assertSame(ES_INDEX, $item[AbstractBulkDeleteRequest::BULK_ACTION]['_index']); $this->assertSame(self::TYPE, $item[AbstractBulkDeleteRequest::BULK_ACTION]['_type']); if (0 === $key) { $this->assertSame(2, $item[AbstractBulkDeleteRequest::BULK_ACTION]['_version']); $this->assertSame(200, $item[AbstractBulkDeleteRequest::BULK_ACTION]['status']); $docRequest = new GetDocumentRequest(ES_INDEX, self::TYPE, $this->getSerializer()); $docRequest->setId($item[AbstractBulkDeleteRequest::BULK_ACTION]['_id']); try { $this->getClient()->send($docRequest); $this->fail('document isn\'t deleted'); } catch (ClientException $exception) { $this->assertSame(404, $exception->getCode()); } } else { $this->assertSame(1, $item[AbstractBulkDeleteRequest::BULK_ACTION]['_version']); $this->assertSame(404, $item[AbstractBulkDeleteRequest::BULK_ACTION]['status']); } } }