Skip to content

Commit

Permalink
ResultCacheStatement lost its cache capability on fetchAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
roger-codina committed Dec 7, 2018
1 parent 9afe404 commit ecddeb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
$this->data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
$this->emptied = true;

return $this->data;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public function testDontFinishNoCache()
self::assertCount(2, $this->sqlLogger->queries);
}

public function testFetchAllAndFinishSavesCache()
{
$layerCache = new ArrayCache();
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'testcachekey', $layerCache));
$stmt->fetchAll();
$stmt->closeCursor();

self::assertCount(1, $layerCache->fetch('testcachekey'));
}

public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode)
{
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey'));
Expand Down

0 comments on commit ecddeb7

Please sign in to comment.