Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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