/** * Data provider for testToArray. * * @return array */ public function getToArrayData() { $out = []; // Case #0 filter aggregation. $aggregation = new FilterAggregation('test_agg'); $filter = new MatchAllFilter(); $aggregation->setFilter($filter); $result = ['filter' => [$filter->getType() => $filter->toArray()]]; $out[] = [$aggregation, $result]; // Case #1 nested filter aggregation. $aggregation = new FilterAggregation('test_agg'); $aggregation->setFilter($filter); $histogramAgg = new HistogramAggregation('acme', 'bar', 10); $aggregation->addAggregation($histogramAgg); $result = ['filter' => [$filter->getType() => $filter->toArray()], 'aggregations' => [$histogramAgg->getName() => $histogramAgg->toArray()]]; $out[] = [$aggregation, $result]; // Case #2 testing bool filter. $aggregation = new FilterAggregation('test_agg'); $matchAllFilter = new MatchAllFilter(); $termFilter = new TermFilter('acme', 'foo'); $boolFilter = new BoolFilter(); $boolFilter->add($matchAllFilter); $boolFilter->add($termFilter); $aggregation->setFilter($boolFilter); $result = ['filter' => [$boolFilter->getType() => $boolFilter->toArray()]]; $out[] = [$aggregation, $result]; return $out; }
/** * Tests toArray() method. */ public function testBoolToArray() { $bool = new BoolFilter(); $bool->add(new TermFilter('key1', 'value1'), 'should'); $bool->add(new TermFilter('key2', 'value2'), 'must'); $bool->add(new TermFilter('key3', 'value3'), 'must_not'); $expected = ['should' => [['term' => ['key1' => 'value1']]], 'must' => [['term' => ['key2' => 'value2']]], 'must_not' => [['term' => ['key3' => 'value3']]]]; $this->assertEquals($expected, $bool->toArray()); }