public function testGetBody()
 {
     $values = ['size' => 100];
     $query = new DocsInIndexTypeQuery();
     $bodyArray = $query->getBody($values);
     $this->assertTrue(is_array($bodyArray));
     $this->assertTrue(isset($bodyArray['aggs']));
     $this->assertTrue(isset($bodyArray['size']));
     $this->assertTrue(isset($bodyArray['aggs']['count_docs_in_index']));
     $subIndex = $bodyArray['aggs']['count_docs_in_index'];
     $this->assertTrue(isset($subIndex['terms']));
     $this->assertTrue(isset($subIndex['terms']['field']));
     $this->assertSame('_index', $subIndex['terms']['field']);
     $this->assertTrue(isset($subIndex['terms']['size']));
     $this->assertSame($values['size'], $subIndex['terms']['size']);
     $this->assertTrue(isset($subIndex['aggs']));
     $this->assertTrue(isset($subIndex['aggs']['count_docs_in_types']));
     $subType = $subIndex['aggs']['count_docs_in_types'];
     $this->assertTrue(isset($subType['terms']));
     $this->assertTrue(isset($subType['terms']['field']));
     $this->assertSame('_type', $subType['terms']['field']);
     $this->assertTrue(isset($subType['terms']['size']));
     $this->assertSame($values['size'], $subType['terms']['size']);
 }
 public function testGetDocCountByIndexType()
 {
     $version = '1.6.0';
     $serverInfoData = $this->getServerInfoData($version);
     $docCount = 88;
     $aggsData['aggregations']['count_docs_in_index']['buckets'] = [['key' => 'my-index', 'doc_count' => $docCount, 'count_docs_in_types' => ['buckets' => [['key' => 'my-type', 'doc_count' => 44]]]]];
     $query = new DocsInIndexTypeQuery();
     $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData);
     $this->response->expects($this->once())->method('getData')->willReturn($aggsData);
     $this->request->expects($this->once())->method('setBody')->with($this->equalTo($query->getBody(array('size' => 10000))))->willReturn(json_encode($aggsData));
     $this->requestFactory->expects($this->once())->method('create')->with('SearchRequest', $version, null, null, $this->serializer)->willReturn($this->request);
     $this->client->expects($this->exactly(2))->method('send')->withConsecutive($this->isInstanceOf('Elastification\\Client\\Request\\V1x\\NodeInfoRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\SearchRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse, $this->response);
     $result = $this->repository->getDocCountByIndexType(self::HOST, self::PORT);
     $this->assertInstanceOf('Elastification\\BackupRestore\\Entity\\IndexTypeStats', $result);
     $this->assertSame($docCount, $result->getDocCount('my-index'));
     $this->assertCount(1, $result->getIndices());
     $index = $result->getIndices()['my-index'];
     $this->assertSame('my-index', $index->getName());
     $this->assertCount(1, $index->getTypes());
     $this->assertSame($docCount, $index->getDocsInIndex());
     $type = $index->getTypes()['my-type'];
     $this->assertSame('my-type', $type->getName());
     $this->assertSame(44, $type->getDocsInType());
 }