public function testAddAction()
 {
     $id1 = 'my-id1';
     $id2 = 'my-id2';
     $action1 = array(AbstractBulkDeleteRequest::BULK_ACTION => array('_id' => $id1, '_index' => self::INDEX, '_type' => self::TYPE));
     $action2 = array(AbstractBulkDeleteRequest::BULK_ACTION => array('_id' => $id2, '_index' => self::INDEX, '_type' => self::TYPE));
     $this->serializer->expects($this->never())->method('serialize');
     $this->request->add(array($id1, $id2));
     $expected = json_encode($action1) . AbstractBulkDeleteRequest::LINE_BREAK . json_encode($action2) . AbstractBulkDeleteRequest::LINE_BREAK;
     $result = $this->request->getBody();
     $this->assertSame($expected, $result);
 }
 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());
     $response = $this->getClient()->send($bulkDeleteRequest);
     $this->assertGreaterThanOrEqual(0, $response->took());
     $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->assertTrue($item[AbstractBulkDeleteRequest::BULK_ACTION]['ok']);
             $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->assertFalse($item[AbstractBulkDeleteRequest::BULK_ACTION]['found']);
         }
     }
 }