Fixed the QueryBuilder::setMaxResults() signature to accept NULL

The original signature was improperly documented which later became enforced.
parent 9728d990
...@@ -122,7 +122,7 @@ class QueryBuilder ...@@ -122,7 +122,7 @@ class QueryBuilder
private $firstResult = 0; private $firstResult = 0;
/** /**
* The maximum number of results to retrieve. * The maximum number of results to retrieve or NULL to retrieve all results.
* *
* @var int|null * @var int|null
*/ */
...@@ -365,7 +365,6 @@ class QueryBuilder ...@@ -365,7 +365,6 @@ class QueryBuilder
/** /**
* Gets the position of the first result the query object was set to retrieve (the "offset"). * Gets the position of the first result the query object was set to retrieve (the "offset").
* Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
* *
* @return int The position of the first result. * @return int The position of the first result.
*/ */
...@@ -377,11 +376,11 @@ class QueryBuilder ...@@ -377,11 +376,11 @@ class QueryBuilder
/** /**
* Sets the maximum number of results to retrieve (the "limit"). * Sets the maximum number of results to retrieve (the "limit").
* *
* @param int $maxResults The maximum number of results to retrieve. * @param int|null $maxResults The maximum number of results to retrieve or NULL to retrieve all results.
* *
* @return $this This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setMaxResults(int $maxResults) : self public function setMaxResults(?int $maxResults) : self
{ {
$this->state = self::STATE_DIRTY; $this->state = self::STATE_DIRTY;
$this->maxResults = $maxResults; $this->maxResults = $maxResults;
...@@ -391,7 +390,7 @@ class QueryBuilder ...@@ -391,7 +390,7 @@ class QueryBuilder
/** /**
* Gets the maximum number of results the query object was set to retrieve (the "limit"). * Gets the maximum number of results the query object was set to retrieve (the "limit").
* Returns NULL if {@link setMaxResults} was not applied to this query builder. * Returns NULL if all results will be returned.
* *
* @return int|null The maximum number of results. * @return int|null The maximum number of results.
*/ */
......
...@@ -474,13 +474,27 @@ class QueryBuilderTest extends DbalTestCase ...@@ -474,13 +474,27 @@ class QueryBuilderTest extends DbalTestCase
self::assertEquals($sql1, $qb->getSQL()); self::assertEquals($sql1, $qb->getSQL());
} }
public function testSetMaxResults() : void /**
* @dataProvider maxResultsProvider
*/
public function testSetMaxResults(?int $maxResults) : void
{ {
$qb = new QueryBuilder($this->conn); $qb = new QueryBuilder($this->conn);
$qb->setMaxResults(10); $qb->setMaxResults($maxResults);
self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEquals(10, $qb->getMaxResults()); self::assertEquals($maxResults, $qb->getMaxResults());
}
/**
* @return mixed[][]
*/
public static function maxResultsProvider() : iterable
{
return [
'non-null' => [10],
'null' => [null],
];
} }
public function testSetFirstResult() : void public function testSetFirstResult() : void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment