Refactored ResultCacheTest for better coverage

parent 4af4999b
...@@ -102,13 +102,13 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -102,13 +102,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
$numExpectedResult[] = array_values($v); $numExpectedResult[] = array_values($v);
} }
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE); $data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE);
self::assertEquals($this->expectedResult, $data); self::assertEquals($this->expectedResult, $data);
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$data = $this->hydrateStmt($stmt, FetchMode::NUMERIC); $data = $this->hydrateStmt($stmt, FetchMode::NUMERIC);
...@@ -124,10 +124,10 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -124,10 +124,10 @@ class ResultCacheTest extends DbalFunctionalTestCase
private function assertStandardAndIteratorFetchAreEqual(int $fetchMode) : void private function assertStandardAndIteratorFetchAreEqual(int $fetchMode) : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$data = $this->hydrateStmt($stmt, $fetchMode); $data = $this->hydrateStmt($stmt, $fetchMode);
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$dataIterator = $this->hydrateStmtIterator($stmt, $fetchMode); $dataIterator = $this->hydrateStmtIterator($stmt, $fetchMode);
self::assertEquals($data, $dataIterator); self::assertEquals($data, $dataIterator);
...@@ -135,7 +135,7 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -135,7 +135,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
public function testDontCloseNoCache() : void public function testDontCloseNoCache() : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$data = []; $data = [];
...@@ -143,7 +143,7 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -143,7 +143,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
$data[] = $row; $data[] = $row;
} }
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$data = []; $data = [];
...@@ -156,12 +156,12 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -156,12 +156,12 @@ class ResultCacheTest extends DbalFunctionalTestCase
public function testDontFinishNoCache() : void public function testDontFinishNoCache() : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$stmt->fetch(FetchMode::ASSOCIATIVE); $stmt->fetch(FetchMode::ASSOCIATIVE);
$stmt->closeCursor(); $stmt->closeCursor();
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
$this->hydrateStmt($stmt, FetchMode::NUMERIC); $this->hydrateStmt($stmt, FetchMode::NUMERIC);
...@@ -171,7 +171,7 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -171,7 +171,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
public function testFetchAllAndFinishSavesCache() : void public function testFetchAllAndFinishSavesCache() : void
{ {
$layerCache = new ArrayCache(); $layerCache = new ArrayCache();
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'testcachekey', $layerCache)); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(0, 'testcachekey', $layerCache));
$stmt->fetchAll(); $stmt->fetchAll();
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -199,13 +199,13 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -199,13 +199,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
*/ */
private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
self::assertEquals(2, $stmt->columnCount()); self::assertEquals(2, $stmt->columnCount());
$data = $this->hydrateStmt($stmt, $fetchMode); $data = $this->hydrateStmt($stmt, $fetchMode);
self::assertEquals($expectedResult, $data); self::assertEquals($expectedResult, $data);
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(0, 'testcachekey'));
self::assertEquals(2, $stmt->columnCount()); self::assertEquals(2, $stmt->columnCount());
$data = $this->hydrateStmt($stmt, $fetchMode); $data = $this->hydrateStmt($stmt, $fetchMode);
...@@ -215,23 +215,24 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -215,23 +215,24 @@ class ResultCacheTest extends DbalFunctionalTestCase
public function testEmptyResultCache() : void public function testEmptyResultCache() : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(0, 'emptycachekey'));
$data = $this->hydrateStmt($stmt); $this->hydrateStmt($stmt);
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(0, 'emptycachekey'));
$data = $this->hydrateStmt($stmt); $this->hydrateStmt($stmt);
self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit');
} }
public function testChangeCacheImpl() : void public function testChangeCacheImpl() : void
{ {
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(0, 'emptycachekey'));
$data = $this->hydrateStmt($stmt); $this->hydrateStmt($stmt);
$secondCache = new ArrayCache(); $secondCache = new ArrayCache();
$stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey', $secondCache));
$data = $this->hydrateStmt($stmt); $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(0, 'emptycachekey', $secondCache));
$this->hydrateStmt($stmt);
self::assertCount(2, $this->sqlLogger->queries, 'two hits'); self::assertCount(2, $this->sqlLogger->queries, 'two hits');
self::assertCount(1, $secondCache->fetch('emptycachekey')); self::assertCount(1, $secondCache->fetch('emptycachekey'));
...@@ -243,7 +244,8 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -243,7 +244,8 @@ class ResultCacheTest extends DbalFunctionalTestCase
private function hydrateStmt(ResultStatement $stmt, int $fetchMode = FetchMode::ASSOCIATIVE) : array private function hydrateStmt(ResultStatement $stmt, int $fetchMode = FetchMode::ASSOCIATIVE) : array
{ {
$data = []; $data = [];
while ($row = $stmt->fetch($fetchMode)) {
foreach ($stmt->fetchAll($fetchMode) as $row) {
$data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment