public function testSetGetBody()
 {
     $body = 'my test body';
     $this->serializer->expects($this->once())->method('serialize')->with($this->equalTo($body), $this->equalTo(array()))->will($this->returnValue($body));
     $this->request->setBody($body);
     $this->assertSame($body, $this->request->getBody());
 }
 public function testCreateDocument()
 {
     $this->createIndex();
     $createDocumentRequest = new CreateDocumentRequest(ES_INDEX, self::TYPE, $this->getSerializer());
     $data = array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000));
     $createDocumentRequest->setBody($data);
     /** @var CreateUpdateDocumentResponse $response */
     $response = $this->getClient()->send($createDocumentRequest);
     $this->assertSame(ES_INDEX, $response->getIndex());
     $this->assertSame(self::TYPE, $response->getType());
     $this->assertSame(1, $response->getVersion());
     $this->assertTrue(strlen($response->getId()) > 5);
     $this->assertTrue($response->created());
 }
 /**
  * @throws \Elastification\Client\Exception\ClientException
  * @throws \Elastification\Client\Exception\RequestException
  * @author Mario Mueller
  */
 public function testThriftConnection()
 {
     $thriftTransport = new ThriftTransport($this->thriftClient);
     $requestManager = new RequestManager();
     $client = new Client($thriftTransport, $requestManager, ClientInterface::ELASTICSEARCH_VERSION_1_3_X);
     $serializer = new NativeJsonSerializer();
     $createDocumentRequest = new CreateDocumentRequest(self::INDEX, self::TYPE, $serializer, ['assoc' => true]);
     $createDocumentRequest->setBody(array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000)));
     /** @var CreateUpdateDocumentResponse $response */
     $timeStart = microtime(true);
     $response = $client->send($createDocumentRequest);
     echo 'createDocument: ' . (microtime(true) - $timeStart) . 's' . PHP_EOL;
     $this->assertSame(self::INDEX, $response->getIndex());
     $this->assertSame(self::TYPE, $response->getType());
     $this->assertSame(1, $response->getVersion());
     $this->assertTrue($response->isOk());
     $this->assertTrue(strlen($response->getId()) > 5);
 }
Example #4
0
 /**
  * Creates on document for a type
  * If no data is given a random dataset will be created with properties: name, value
  *
  * @param string $type
  * @param null|array|object $data
  *
  * @return string
  */
 protected function createDocument($type, $data = null)
 {
     $createDocumentRequest = new CreateDocumentRequest(ES_INDEX, $type, $this->serializer);
     if (null === $data) {
         $data = array('name' => 'test' . rand(100, 10000), 'value' => 'myTestVal' . rand(100, 10000));
     }
     $createDocumentRequest->setBody($data);
     /** @var CreateUpdateDocumentResponse $response */
     $response = $this->client->send($createDocumentRequest);
     return $response->getId();
 }