/** * Test for anonymous filters. */ public function testAnonymousFiltersAggregation() { $repo = $this->getManager()->getRepository('AcmeTestBundle:Product'); $aggregation = new FiltersAggregation('test_agg'); $aggregation->setAnonymous(true); $aggregation->addFilter(new TermFilter('title', 'bar')); $search = $repo->createSearch()->addAggregation($aggregation); $results = $repo->execute($search, Repository::RESULTS_RAW); $this->assertEquals(1, $results['aggregations']['agg_test_agg']['buckets'][0]['doc_count']); }
/** * Test for filter aggregation toArray() method. */ public function testToArray() { $aggregation = new FiltersAggregation('test_agg'); $filter = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\DSL\\BuilderInterface')->setMethods(['toArray', 'getType'])->getMockForAbstractClass(); $filter->expects($this->any())->method('getType')->willReturn('test_filter'); $filter->expects($this->any())->method('toArray')->willReturn(['test_field' => ['test_value' => 'test']]); $aggregation->addFilter($filter, 'first'); $aggregation->addFilter($filter, 'second'); $results = $aggregation->toArray(); $expected = ['agg_test_agg' => ['filters' => ['filters' => ['first' => ['test_filter' => ['test_field' => ['test_value' => 'test']]], 'second' => ['test_filter' => ['test_field' => ['test_value' => 'test']]]]]]]; $this->assertEquals($expected, $results); }