Skip to content

Commit

Permalink
CS (alignment, imports, short array syntax, list assignments)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed May 3, 2017
1 parent 00f13ca commit a1b0106
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\Tests\DbalTestCase;
use PDO;

class QueryCacheProfileTest extends DbalTestCase
{
Expand All @@ -21,44 +22,44 @@ protected function setUp()
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,
Expand All @@ -67,86 +68,78 @@ public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven()

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

0 comments on commit a1b0106

Please sign in to comment.