Skip to content

Commit

Permalink
Fixed the QueryBuilder::setMaxResults() signature to accept NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 22, 2020
1 parent e5d1edc commit 9b7246a
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 @@ -118,9 +118,9 @@ class QueryBuilder
private $firstResult = null;

/**
* The maximum number of results to retrieve.
* The maximum number of results to retrieve or NULL to retrieve all results.
*
* @var int
* @var int|null
*/
private $maxResults = null;

Expand Down Expand Up @@ -367,7 +367,6 @@ public function setFirstResult($firstResult)

/**
* 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 @@ -379,7 +378,7 @@ public function getFirstResult()
/**
* 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.
*/
Expand All @@ -393,7 +392,7 @@ public function setMaxResults($maxResults)

/**
* 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 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 @@ -569,13 +569,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 9b7246a

Please sign in to comment.