Skip to content

Commit

Permalink
Merge pull request #3840 from morozov/max-results-null
Browse files Browse the repository at this point in the history
Fixed the QueryBuilder::setMaxResults() signature to accept NULL
  • Loading branch information
morozov authored Jan 22, 2020
2 parents 4d9a08c + bf2dc10 commit 7027ec9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 4 additions & 5 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class QueryBuilder
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
*/
Expand Down Expand Up @@ -365,7 +365,6 @@ public function setFirstResult(int $firstResult) : self

/**
* 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.
*/
Expand All @@ -377,11 +376,11 @@ public function getFirstResult() : int
/**
* 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.
*/
public function setMaxResults(int $maxResults) : self
public function setMaxResults(?int $maxResults) : self
{
$this->state = self::STATE_DIRTY;
$this->maxResults = $maxResults;
Expand All @@ -391,7 +390,7 @@ public function setMaxResults(int $maxResults) : self

/**
* 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.
*/
Expand Down
20 changes: 17 additions & 3 deletions tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,27 @@ public function testGetState() : void
self::assertEquals($sql1, $qb->getSQL());
}

public function testSetMaxResults() : void
/**
* @dataProvider maxResultsProvider
*/
public function testSetMaxResults(?int $maxResults) : void
{
$qb = new QueryBuilder($this->conn);
$qb->setMaxResults(10);
$qb->setMaxResults($maxResults);

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
Expand Down

0 comments on commit 7027ec9

Please sign in to comment.