Skip to content

Commit

Permalink
[BUGFIX] Reset number of results in QueryResult after offset changes
Browse files Browse the repository at this point in the history
Using offsetSet or unset allows manipulating the QueryResult manually.
As the result of `count` is cached, offset changes need to reset that
cache to accurately return the correct offset.

Resolves: #76310
Releases: master, 9.5
Change-Id: Ic43f3810766bdb1ee02800b07f6853c81ba404f5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63896
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
susannemoog authored and georgringer committed Mar 26, 2020
1 parent 47360d8 commit 50d757d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -192,6 +192,7 @@ public function offsetGet($offset)
public function offsetSet($offset, $value)
{
$this->initialize();
$this->numberOfResults = null;
$this->queryResult[$offset] = $value;
}

Expand All @@ -204,6 +205,7 @@ public function offsetSet($offset, $value)
public function offsetUnset($offset)
{
$this->initialize();
$this->numberOfResults = null;
unset($this->queryResult[$offset]);
}

Expand Down
Expand Up @@ -158,6 +158,24 @@ public function countOnlyCallsGetObjectCountByQueryOnPersistenceManagerOnce()
$this->assertEquals(2, $this->queryResult->count());
}

/**
* @test
*/
public function countCallsGetObjectCountByQueryIfOffsetChanges()
{
$this->mockPersistenceManager->expects(self::once())->method('getObjectCountByQuery')->willReturn(2);
$firstCount = $this->queryResult->count();
$this->queryResult->offsetSet(3, new \stdClass());
$this->queryResult->offsetSet(4, new \stdClass());
$secondCount = $this->queryResult->count();
$this->queryResult->offsetUnset(1);
$thirdCount = $this->queryResult->count();

self::assertSame(2, $firstCount);
self::assertSame(4, $secondCount);
self::assertSame(3, $thirdCount);
}

/**
* @test
*/
Expand Down

0 comments on commit 50d757d

Please sign in to comment.