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());
 }
Esempio n. 3
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();
 }