<commit_before><?php

namespace Elastica\Test\Aggregation;


use Elastica\Aggregation\Cardinality;
use Elastica\Document;
use Elastica\Query;

class CardinalityTest extends BaseAggregationTest
{
    protected function setUp()
    {
        parent::setUp();
        $this->_index = $this->_createIndex("cardinality");
        $docs = array(
            new Document("1", array("color" => "blue")),
            new Document("2", array("color" => "blue")),
            new Document("3", array("color" => "red")),
            new Document("4", array("color" => "green")),
        );
        $this->_index->getType("test")->addDocuments($docs);
        $this->_index->refresh();
    }

    public function testCardinalityAggregation()
    {
        $agg = new Cardinality("cardinality");
        $agg->setField("color");

        $query = new Query();
        $query->addAggregation($agg);
        $results = $this->_index->search($query)->getAggregation("cardinality");

        $this->assertEquals(3, $result['value']);
    }
}
 <commit_msg>Fixed test for Cardinality aggregation<commit_after><?php

namespace Elastica\Test\Aggregation;


use Elastica\Aggregation\Cardinality;
use Elastica\Document;
use Elastica\Query;

class CardinalityTest extends BaseAggregationTest
{
    protected function setUp()
    {
        parent::setUp();
        $this->_index = $this->_createIndex("cardinality");
        $docs = array(
            new Document("1", array("color" => "blue")),
            new Document("2", array("color" => "blue")),
            new Document("3", array("color" => "red")),
            new Document("4", array("color" => "green")),
        );
        $this->_index->getType("test")->addDocuments($docs);
        $this->_index->refresh();
    }

    public function testCardinalityAggregation()
    {
        $agg = new Cardinality("cardinality");
        $agg->setField("color");

        $query = new Query();
        $query->addAggregation($agg);
        $results = $this->_index->search($query)->getAggregation("cardinality");

        $this->assertEquals(3, $results['value']);
    }
}
 
{'fraction_non_alphanumeric': 0.1731684110371075, 'fraction_numerical': 0.004757373929590866, 'mean_word_length': 2.930841121495327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6716305', 'n_tokens_mistral': 621, 'n_tokens_neox': 607, 'n_words': 112}