/**
  * Test for reverse_nested aggregation toArray() without path.
  */
 public function testToArrayNoPath()
 {
     $termMock = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\Aggregation\\TermsAggregation')->disableOriginalConstructor()->getMock();
     $termMock->expects($this->once())->method('toArray')->will($this->returnValue(['terms' => []]));
     $aggregation = new ReverseNestedAggregation('test_nested_agg');
     $aggregation->addAggregation($termMock);
     $expectedResult = ['agg_test_nested_agg' => ['reverse_nested' => new \stdClass(), 'aggregations' => ['terms' => []]]];
     $this->assertEquals($expectedResult, $aggregation->toArray());
 }
 /**
  * Test for reverse nested terms aggregation.
  *
  * @param AbstractAggregation $aggregation
  * @param AbstractAggregation $reverseAggregation
  * @param array               $expectedResult
  * @param array               $mapping
  *
  * @dataProvider getReverseNestedAggregationData
  */
 public function testReverseNestedAggregation($aggregation, $reverseAggregation, $expectedResult, $mapping)
 {
     $repository = $this->getManager('default', true, $mapping)->getRepository('AcmeTestBundle:Product');
     $revereNestedAggregation = new ReverseNestedAggregation('test_reverse_nested_agg');
     $revereNestedAggregation->addAggregation($reverseAggregation);
     $aggregation->addAggregation($revereNestedAggregation);
     $nestedAggregation = new NestedAggregation('test_nested_agg');
     $nestedAggregation->setPath('sub_products');
     $nestedAggregation->addAggregation($aggregation);
     $search = $repository->createSearch()->addAggregation($nestedAggregation);
     $results = $repository->execute($search, Repository::RESULTS_RAW);
     $this->assertArrayHasKey('aggregations', $results);
     $this->assertArraySubset($expectedResult, $results['aggregations']['agg_test_nested_agg']);
 }