Commit a1b01060 authored by Marco Pivetta's avatar Marco Pivetta

CS (alignment, imports, short array syntax, list assignments)

parent 00f13ca3
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Cache;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\Tests\DbalTestCase;
use PDO;
class QueryCacheProfileTest extends DbalTestCase
{
......@@ -21,44 +22,44 @@ class QueryCacheProfileTest extends DbalTestCase
public function testShouldUseTheGivenCacheKeyIfPresent()
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = array(666);
$types = array(\PDO::PARAM_INT);
$params = [666];
$types = [PDO::PARAM_INT];
$connectionParams = array(
'dbname' => 'database_name',
'user' => 'database_user',
'dbname' => 'database_name',
'user' => 'database_user',
'password' => 'database_password',
'host' => 'database_host',
'driver' => 'database_driver'
'host' => 'database_host',
'driver' => 'database_driver'
);
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($cacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
$connectionParams
);
$this->assertEquals(self::CACHE_KEY, $generatedKeys[0], 'The returned cache key should match the given one');
$this->assertEquals(self::CACHE_KEY, $cacheKey, 'The returned cache key should match the given one');
}
public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven()
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = array(666);
$types = array(\PDO::PARAM_INT);
$params = [666];
$types = [PDO::PARAM_INT];
$connectionParams = array(
'dbname' => 'database_name',
'user' => 'database_user',
'dbname' => 'database_name',
'user' => 'database_user',
'password' => 'database_password',
'host' => 'database_host',
'driver' => 'database_driver'
'host' => 'database_host',
'driver' => 'database_driver'
);
$this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null);
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($cacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
......@@ -67,86 +68,78 @@ class QueryCacheProfileTest extends DbalTestCase
$this->assertNotEquals(
self::CACHE_KEY,
$generatedKeys[0],
$cacheKey,
'The returned cache key should be generated automatically'
);
$this->assertNotEmpty($generatedKeys[0], 'The generated cache key should not be empty');
$this->assertNotEmpty($cacheKey, 'The generated cache key should not be empty');
}
public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferentConnections()
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = array(666);
$types = array(\PDO::PARAM_INT);
$params = [666];
$types = [PDO::PARAM_INT];
$connectionParams = array(
'dbname' => 'database_name',
'user' => 'database_user',
'dbname' => 'database_name',
'user' => 'database_user',
'password' => 'database_password',
'host' => 'database_host',
'driver' => 'database_driver'
'host' => 'database_host',
'driver' => 'database_driver'
);
$this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null);
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
$connectionParams
);
$firstCacheKey = $generatedKeys[0];
$connectionParams['host'] = 'a_different_host';
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
$connectionParams
);
$secondCacheKey = $generatedKeys[0];
$this->assertNotEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be different');
}
public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges()
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = array(666);
$types = array(\PDO::PARAM_INT);
$params = [666];
$types = [PDO::PARAM_INT];
$connectionParams = array(
'dbname' => 'database_name',
'user' => 'database_user',
'dbname' => 'database_name',
'user' => 'database_user',
'password' => 'database_password',
'host' => 'database_host',
'driver' => 'database_driver'
'host' => 'database_host',
'driver' => 'database_driver'
);
$this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null);
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
$connectionParams
);
$firstCacheKey = $generatedKeys[0];
$generatedKeys = $this->queryCacheProfile->generateCacheKeys(
list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys(
$query,
$params,
$types,
$connectionParams
);
$secondCacheKey = $generatedKeys[0];
$this->assertEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be the same');
}
}
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