Skip to content

Commit

Permalink
Maintain platform parameter in connection params but remove it before
Browse files Browse the repository at this point in the history
using params in query cache key generation.
  • Loading branch information
jwage committed Apr 17, 2019
1 parent 3a0a1d1 commit f202e76
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public function __construct(
}

$this->platform = $params['platform'];
unset($this->params['platform']);
}

// Create default config and event manager if none given
Expand Down Expand Up @@ -932,7 +931,10 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc
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);
Expand Down
51 changes: 51 additions & 0 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,4 +880,55 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting

$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);
}
}

0 comments on commit f202e76

Please sign in to comment.