Skip to content

Commit

Permalink
tests, that fix toArray cast logic for #783
Browse files Browse the repository at this point in the history
  • Loading branch information
ewgRa committed Mar 18, 2015
1 parent 59c1a4c commit 5e13558
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions test/lib/Elastica/Test/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Elastica\Query\Builder;
use Elastica\Query\Term;
use Elastica\Query\Text;
use Elastica\Script;
use Elastica\ScriptFields;
use Elastica\Suggest;
use Elastica\Test\Base as BaseTest;

Expand Down Expand Up @@ -216,4 +218,142 @@ public function testSetFacets()

$this->assertArrayNotHasKey('facets', $query->toArray());
}

public function testSetQueryToArrayCast()
{
$query = new Query();
$termQuery = new Term();
$termQuery->setTerm('text', 'value');
$query->setQuery($termQuery);

$termQuery->setTerm('text', 'another value');

$anotherQuery = new Query();
$anotherQuery->setQuery($termQuery);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testSetQueryToArrayChangeQuery()
{
$query = new Query();
$termQuery = new Term();
$termQuery->setTerm('text', 'value');
$query->setQuery($termQuery);

$queryArray = $query->toArray();

$termQuery = $query->getQuery();
$termQuery['term']['text']['value'] = 'another value';

$this->assertEquals($queryArray, $query->toArray());
}

public function testSetScriptFieldsToArrayCast()
{
$query = new Query();
$scriptFields = new ScriptFields();
$scriptFields->addScript('script', new Script('script'));

$query->setScriptFields($scriptFields);

$scriptFields->addScript('another script', new Script('another script'));

$anotherQuery = new Query();
$anotherQuery->setScriptFields($scriptFields);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testAddScriptFieldsToArrayCast()
{
$query = new Query();
$scriptField = new Script('script');

$query->addScriptField('script', $scriptField);

$scriptField->setScript('another script');

$anotherQuery = new Query();
$anotherQuery->addScriptField('script', $scriptField);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testAddFacetToArrayCast()
{
$query = new Query();
$facet = new Terms('text');

$query->addFacet($facet);

$facet->setName('another text');

$anotherQuery = new Query();
$anotherQuery->addFacet($facet);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testAddAggregationToArrayCast()
{
$query = new Query();
$aggregation = new \Elastica\Aggregation\Terms('text');

$query->addAggregation($aggregation);

$aggregation->setName('another text');

$anotherQuery = new Query();
$anotherQuery->addAggregation($aggregation);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testSetSuggestToArrayCast()
{
$query = new Query();
$suggest = new Suggest();
$suggest->setGlobalText('text');

$query->setSuggest($suggest);

$suggest->setGlobalText('another text');

$anotherQuery = new Query();
$anotherQuery->setSuggest($suggest);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testSetRescoreToArrayCast()
{
$query = new Query();
$rescore = new \Elastica\Rescore\Query();
$rescore->setQueryWeight(1);

$query->setRescore($rescore);

$rescore->setQueryWeight(2);

$anotherQuery = new Query();
$anotherQuery->setRescore($rescore);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}

public function testSetPostFilterToArrayCast()
{
$query = new Query();
$postFilter = new \Elastica\Filter\Terms();
$postFilter->setTerms('key', array('term'));
$query->setPostFilter($postFilter);

$postFilter->setTerms('another key', array('another term'));

$anotherQuery = new Query();
$anotherQuery->setPostFilter($postFilter);

$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}
}

0 comments on commit 5e13558

Please sign in to comment.