/**
  * Test getArray method.
  */
 public function testDateRangeAggregationGetArray()
 {
     $agg = new DateRangeAggregation('foo');
     $agg->addRange(10, 20);
     $agg->setFormat('bar');
     $agg->setField('baz');
     $result = $agg->getArray();
     $expected = ['format' => 'bar', 'field' => 'baz', 'ranges' => [['from' => 10, 'to' => 20]]];
     $this->assertEquals($expected, $result);
 }
 /**
  * Test when multiple ranges are set and to is null.
  */
 public function testDateRangeWhenToIsNull()
 {
     $repo = $this->getManager()->getRepository('AcmeTestBundle:Comment');
     $aggregation = new DateRangeAggregation('date_range');
     $aggregation->setField('createdAt');
     $aggregation->setFormat('Y');
     $aggregation->addRange('2011', '2015');
     $aggregation->addRange('2014', null);
     $expectedResults = ['agg_date_range' => ['buckets' => [['key' => '2011-2015', 'from' => '1293840000000', 'from_as_string' => '2011', 'to' => '1420070400000', 'to_as_string' => '2015', 'doc_count' => 2], ['key' => '2014-*', 'from' => '1388534400000', 'from_as_string' => '2014', 'doc_count' => 1]]]];
     $search = $repo->createSearch()->addAggregation($aggregation);
     $results = $repo->execute($search, Repository::RESULTS_RAW);
     $this->assertArrayHasKey('aggregations', $results);
     $this->assertEquals($expectedResults, $results['aggregations']);
 }