/**
  * Tests percentiles aggregation using script instead of field.
  */
 public function testPercentilesAggregationWithScript()
 {
     $repository = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $aggregation = new PercentilesAggregation('foo');
     $aggregation->setScript("doc['product.price'].value / 10");
     $search = $repository->createSearch()->addAggregation($aggregation);
     /** @var ValueAggregation $result */
     $result = $repository->execute($search)->getAggregations()->find('foo');
     $expectedResults = ['1.0' => 1.015, '5.0' => 1.075, '25.0' => 1.375, '50.0' => 2.0, '75.0' => 2.5, '95.0' => 2.5, '99.0' => 2.5];
     $this->assertEquals($expectedResults, $result->getValue()['values']);
 }
 /**
  * Tests if PercentilesAggregation#getArray throws exception when expected.
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage Percentiles aggregation must have field or script set.
  */
 public function testPercentilesAggregationGetArrayException()
 {
     $aggregation = new PercentilesAggregation('bar');
     $aggregation->getArray();
 }