/**
  * Tests if filters can be passed to constructor.
  */
 public function testConstructorFilter()
 {
     /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
     $builderInterface1 = $this->getMockForAbstractClass('ONGR\\ElasticsearchDSL\\BuilderInterface');
     /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
     $builderInterface2 = $this->getMockForAbstractClass('ONGR\\ElasticsearchDSL\\BuilderInterface');
     $aggregation = new FiltersAggregation('test', ['filter1' => $builderInterface1, 'filter2' => $builderInterface2]);
     $this->assertSame(['filters' => ['filters' => ['filter1' => null, 'filter2' => null]]], $aggregation->toArray());
     $aggregation = new FiltersAggregation('test', ['filter1' => $builderInterface1, 'filter2' => $builderInterface2], true);
     $this->assertSame(['filters' => ['filters' => [null, null]]], $aggregation->toArray());
 }
 /**
  * Test for filter aggregation toArray() method.
  */
 public function testToArray()
 {
     $aggregation = new FiltersAggregation('test_agg');
     $filter = $this->getMockBuilder('ONGR\\ElasticsearchDSL\\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);
 }
Ejemplo n.º 3
0
 /**
  * Tests integration of the FiltersAggregation anonymous example from the documentation.
  *
  * @link https://github.com/ongr-io/ElasticsearchDSL/blob/master/docs/Aggregation/Filters.md#anonymous-example
  */
 public function testFiltersAggregationAnonymousExample()
 {
     $errorTermFilter = new TermQuery('body', 'error');
     $warningTermFilter = new TermQuery('body', 'warning');
     $histogramAggregation = new HistogramAggregation('monthly', 'timestamp');
     $histogramAggregation->setInterval('1M');
     $filterAggregation = new FiltersAggregation('grades_stats', ['error' => $errorTermFilter, 'warning' => $warningTermFilter], true);
     $filterAggregation->addAggregation($histogramAggregation);
     $search = new Search();
     $search->addAggregation($filterAggregation);
     $this->assertSame(['aggregations' => ['grades_stats' => ['filters' => ['filters' => [['term' => ['body' => 'error']], ['term' => ['body' => 'warning']]]], 'aggregations' => ['monthly' => ['histogram' => ['field' => 'timestamp', 'interval' => '1M']]]]]], $search->toArray());
 }
 /**
  * Tests if filters can be passed to constructor.
  */
 public function testConstructorFilter()
 {
     /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
     $builderInterface1 = $this->getMockForAbstractClass('ONGR\\ElasticsearchDSL\\BuilderInterface');
     $builderInterface1->expects($this->any())->method('getType')->willReturn('type1');
     /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
     $builderInterface2 = $this->getMockForAbstractClass('ONGR\\ElasticsearchDSL\\BuilderInterface');
     $builderInterface2->expects($this->any())->method('getType')->willReturn('type2');
     $aggregation = new FiltersAggregation('test', ['filter1' => $builderInterface1, 'filter2' => $builderInterface2]);
     $this->assertSame(['filters' => ['filters' => ['filter1' => ['type1' => null], 'filter2' => ['type2' => null]]]], $aggregation->toArray());
     $aggregation = new FiltersAggregation('test', ['filter1' => $builderInterface1, 'filter2' => $builderInterface2], true);
     $this->assertSame(['filters' => ['filters' => [['type1' => null], ['type2' => null]]]], $aggregation->toArray());
 }