Skip to content
Snippets Groups Projects
Commit ef5c2e16 authored by Simonas Šerlinskas's avatar Simonas Šerlinskas Committed by GitHub
Browse files

Merge pull request #159 from niels-nijens/fix-boolquery-getqueries

Fix notice in BoolQuery::getQueries when nothing is added to bool type
parents d8232294 de17c854
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,10 @@ class BoolQuery implements BuilderInterface
}
/**
* @param null $boolType
* Returns the query instances (by bool type).
*
* @param string|null $boolType
*
* @return array
*/
public function getQueries($boolType = null)
......@@ -57,7 +60,11 @@ class BoolQuery implements BuilderInterface
return $queries;
}
return $this->container[$boolType];
if (isset($this->container[$boolType])) {
return $this->container[$boolType];
}
return [];
}
/**
......
......@@ -112,4 +112,54 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase
];
$this->assertEquals($expected, $bool->toArray());
}
/**
* Tests if BoolQuery::getQueries returns an empty array.
*/
public function testGetQueriesEmpty()
{
$bool = new BoolQuery();
$this->assertInternalType('array', $bool->getQueries());
}
/**
* Tests if BoolQuery::getQueries returns an array with the added queries of all bool types.
*/
public function testGetQueries()
{
$query = new TermQuery('key1', 'value1');
$query2 = new TermQuery('key2', 'value2');
$bool = new BoolQuery();
$bool->add($query, BoolQuery::MUST, 'query');
$bool->add($query2, BoolQuery::SHOULD, 'query2');
$this->assertSame(array('query' => $query, 'query2' => $query2), $bool->getQueries());
}
/**
* Tests if BoolQuery::getQueries with specified bool type returns an empty array.
*/
public function testGetQueriesByBoolTypeEmpty()
{
$bool = new BoolQuery();
$this->assertInternalType('array', $bool->getQueries(BoolQuery::MUST));
}
/**
* Tests if BoolQuery::getQueries with specified bool type returns an array with added queries.
*/
public function testGetQueriesByBoolTypeWithQueryAddedToBoolType()
{
$query = new TermQuery('key1', 'value1');
$query2 = new TermQuery('key2', 'value2');
$bool = new BoolQuery();
$bool->add($query, BoolQuery::MUST, 'query');
$bool->add($query2, BoolQuery::SHOULD, 'query2');
$this->assertSame(array('query' => $query), $bool->getQueries(BoolQuery::MUST));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment