Maintain platform parameter in connection params but remove it before

using params in query cache key generation.
parent 3a0a1d10
......@@ -200,7 +200,6 @@ class Connection implements DriverConnection
}
$this->platform = $params['platform'];
unset($this->params['platform']);
}
// Create default config and event manager if none given
......@@ -932,7 +931,10 @@ class Connection implements DriverConnection
throw CacheException::noResultDriverConfigured();
}
[$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams());
$connectionParams = $this->getParams();
unset($connectionParams['platform']);
[$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $connectionParams);
// fetch the row pointers entry
$data = $resultCache->fetch($cacheKey);
......
......@@ -880,4 +880,55 @@ class ConnectionTest extends DbalTestCase
$connection->getDatabasePlatform();
}
/**
* @group #3194
*/
public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void
{
/** @var Driver|MockObject $driver */
$driver = $this->createMock(Driver::class);
/** @var AbstractPlatform|MockObject $platform */
$platform = $this->createMock(AbstractPlatform::class);
/** @var QueryCacheProfile|MockObject $queryCacheProfile */
$queryCacheProfile = $this->createMock(QueryCacheProfile::class);
/** @var Cache|MockObject $resultCacheDriver */
$resultCacheDriver = $this->createMock(Cache::class);
$queryCacheProfile
->expects($this->any())
->method('getResultCacheDriver')
->will($this->returnValue($resultCacheDriver));
$resultCacheDriver
->expects($this->atLeastOnce())
->method('fetch')
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
$query = 'SELECT 1';
$params = [
'dbname' => 'foo',
'platform' => $platform,
];
$paramsWithoutPlatform = $params;
unset($paramsWithoutPlatform['platform']);
$queryCacheProfile
->expects($this->once())
->method('generateCacheKeys')
->with($query, [], [], $paramsWithoutPlatform)
->will($this->returnValue(['cacheKey', 'realKey']));
$connection = new Connection($params, $driver);
self::assertSame($params, $connection->getParams());
$connection->executeCacheQuery($query, [], [], $queryCacheProfile);
}
}
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