/**
  * Test for cardinality aggregation.
  *
  * @param int  $threshold
  * @param bool $rehash
  * @param int  $expectedResults
  *
  * @dataProvider getCardinalityAggregationData()
  */
 public function testCardinalityAggregation($threshold, $rehash, $expectedResults)
 {
     /** @var Repository $repo */
     $repo = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $aggregation = new CardinalityAggregation('test_agg');
     $aggregation->setField('price');
     $aggregation->setPrecisionThreshold($threshold);
     $aggregation->setRehash($rehash);
     $search = $repo->createSearch()->addAggregation($aggregation);
     $results = $repo->execute($search, Repository::RESULTS_OBJECT);
     /** @var ValueAggregation $result */
     $result = $results->getAggregations()['test_agg'];
     $this->assertEquals($expectedResults, $result->getValue()['value']);
 }
 /**
  * Tests getArray method.
  */
 public function testGetArray()
 {
     $aggregation = new CardinalityAggregation('bar');
     $aggregation->setScript('foo');
     $result = $aggregation->getArray();
     $this->assertArrayHasKey('script', $result, 'key=script when script is set');
     $this->assertEquals('foo', $result['script'], 'script=foo when scripts name=foo');
     $aggregation->setField('foo');
     $result = $aggregation->getArray();
     $this->assertArrayHasKey('field', $result, 'key=field when field is set');
     $this->assertEquals('foo', $result['field'], 'field=foo when fields name=foo');
     $aggregation->setPrecisionThreshold(10);
     $result = $aggregation->getArray();
     $this->assertArrayHasKey('precision_threshold', $result, 'key=precision_threshold when is set');
     $this->assertEquals(10, $result['precision_threshold'], 'precision_threshold=10 when is set');
     $aggregation->setRehash(true);
     $result = $aggregation->getArray();
     $this->assertArrayHasKey('rehash', $result, 'key=rehash when rehash is set');
     $this->assertEquals(true, $result['rehash'], 'rehash=true when rehash is set to true');
 }