/** * Test for nested aggregation toArray() method exception. */ public function testToArray() { $termMock = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\Aggregation\\TermsAggregation')->disableOriginalConstructor()->getMock(); $termMock->expects($this->once())->method('toArray')->will($this->returnValue(['terms' => []])); $aggregation = new NestedAggregation('test_nested_agg'); $aggregation->setPath('test_path'); $aggregation->addAggregation($termMock); $expectedResult = ['agg_test_nested_agg' => ['nested' => ['path' => 'test_path'], 'aggregations' => ['terms' => []]]]; $this->assertEquals($expectedResult, $aggregation->toArray()); }
/** * Test for nested terms aggregation. * * @param TermsAggregation $aggregation * @param array $expectedResult * @param array $mapping * * @dataProvider getNestedAggregationData */ public function testNestedAggregation($aggregation, $expectedResult, $mapping) { /** @var Repository $repo */ $repo = $this->getManager('default', true, $mapping)->getRepository('AcmeTestBundle:Product'); $nestedAggregation = new NestedAggregation('test_nested_agg'); $nestedAggregation->setPath('sub_products'); $nestedAggregation->addAggregation($aggregation); $search = $repo->createSearch()->addAggregation($nestedAggregation); $results = $repo->execute($search, Repository::RESULTS_RAW); $this->assertArrayHasKey('aggregations', $results); $this->assertArraySubset($expectedResult, $results['aggregations']['agg_test_nested_agg']); }