Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
d19567bc
Commit
d19567bc
authored
Nov 08, 2014
by
Antonio Vilar
Committed by
Marco Pivetta
May 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new tests for QueryCacheProfile and Connection
parent
a60be246
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
20 deletions
+124
-20
QueryCacheProfileTest.php
tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
+90
-20
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+34
-0
No files found.
tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
View file @
d19567bc
...
@@ -20,10 +20,7 @@ class QueryCacheProfileTest extends DbalTestCase
...
@@ -20,10 +20,7 @@ class QueryCacheProfileTest extends DbalTestCase
$this
->
queryCacheProfile
=
new
QueryCacheProfile
(
self
::
LIFETIME
,
self
::
CACHE_KEY
);
$this
->
queryCacheProfile
=
new
QueryCacheProfile
(
self
::
LIFETIME
,
self
::
CACHE_KEY
);
}
}
/**
public
function
testShouldUseTheGivenCacheKeyIfPresent
()
* @test
*/
public
function
it_should_use_the_given_cache_key_if_present
()
{
{
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$params
=
array
(
666
);
$params
=
array
(
666
);
...
@@ -37,20 +34,43 @@ class QueryCacheProfileTest extends DbalTestCase
...
@@ -37,20 +34,43 @@ class QueryCacheProfileTest extends DbalTestCase
'driver'
=>
'database_driver'
'driver'
=>
'database_driver'
);
);
$expectedRealCacheKey
=
'query=SELECT * FROM foo WHERE bar = ?¶ms=a:1:{i:0;i:666;}&types=a:1:{i:0;'
$generatedKeys
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
.
'i:1;}a:5:{s:6:"dbname";s:13:"database_name";s:4:"user";s:13:"database_user";s:8:"password";s:17:"'
$query
,
.
'database_password";s:4:"host";s:13:"database_host";s:6:"driver";s:15:"database_driver";}'
;
$params
,
$types
,
$connectionParams
);
$this
->
assertEquals
(
self
::
CACHE_KEY
,
$generatedKeys
[
0
],
'The returned cached key should match the given one'
);
}
public
function
testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven
()
{
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$params
=
array
(
666
);
$types
=
array
(
\PDO
::
PARAM_INT
);
$connectionParams
=
array
(
'dbname'
=>
'database_name'
,
'user'
=>
'database_user'
,
'password'
=>
'database_password'
,
'host'
=>
'database_host'
,
'driver'
=>
'database_driver'
);
$this
->
queryCacheProfile
=
$this
->
queryCacheProfile
->
setCacheKey
(
null
);
$cacheKeysResult
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$generatedKeys
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$this
->
assertEquals
(
self
::
CACHE_KEY
,
$cacheKeysResult
[
0
],
'The returned cached key should match the given one'
);
$this
->
assertNotEmpty
(
$generatedKeys
[
0
],
'The generated cache key should not be empty'
);
$this
->
assertEquals
(
$expectedRealCacheKey
,
$cacheKeysResult
[
1
]);
}
}
/**
public
function
testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferentConnections
()
* @test
*/
public
function
it_should_generate_an_automatic_key_if_no_key_has_been_specified
()
{
{
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$params
=
array
(
666
);
$params
=
array
(
666
);
...
@@ -64,15 +84,65 @@ class QueryCacheProfileTest extends DbalTestCase
...
@@ -64,15 +84,65 @@ class QueryCacheProfileTest extends DbalTestCase
'driver'
=>
'database_driver'
'driver'
=>
'database_driver'
);
);
$expectedRealCacheKey
=
'query=SELECT * FROM foo WHERE bar = ?¶ms=a:1:{i:0;i:666;}&types=a:1:{i:0;'
$this
->
queryCacheProfile
=
$this
->
queryCacheProfile
->
setCacheKey
(
null
);
.
'i:1;}a:5:{s:6:"dbname";s:13:"database_name";s:4:"user";s:13:"database_user";s:8:"password";s:17:"'
.
'database_password";s:4:"host";s:13:"database_host";s:6:"driver";s:15:"database_driver";}'
;
$generatedKeys
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$firstCacheKey
=
$generatedKeys
[
0
];
$connectionParams
[
'host'
]
=
'a_different_host'
;
$generatedKeys
=
$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
);
$connectionParams
=
array
(
'dbname'
=>
'database_name'
,
'user'
=>
'database_user'
,
'password'
=>
'database_password'
,
'host'
=>
'database_host'
,
'driver'
=>
'database_driver'
);
$this
->
queryCacheProfile
=
$this
->
queryCacheProfile
->
setCacheKey
(
null
);
$this
->
queryCacheProfile
=
$this
->
queryCacheProfile
->
setCacheKey
(
null
);
$cacheKeysResult
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$generatedKeys
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$firstCacheKey
=
$generatedKeys
[
0
];
$generatedKeys
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$secondCacheKey
=
$generatedKeys
[
0
];
$this
->
assertEquals
(
'8f74136f51719d57f4da9b6d2ba955b42189bb81'
,
$cacheKeysResult
[
0
]);
$this
->
assertEquals
(
$firstCacheKey
,
$secondCacheKey
,
'Cache keys should be the same'
);
$this
->
assertEquals
(
$expectedRealCacheKey
,
$cacheKeysResult
[
1
]);
}
}
}
}
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
d19567bc
...
@@ -670,4 +670,38 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
...
@@ -670,4 +670,38 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertSame
(
$platformMock
,
$connection
->
getDatabasePlatform
());
$this
->
assertSame
(
$platformMock
,
$connection
->
getDatabasePlatform
());
}
}
public
function
testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery
()
{
$resultCacheDriverMock
=
$this
->
getMock
(
'Doctrine\Common\Cache\Cache'
);
$resultCacheDriverMock
->
expects
(
$this
->
any
())
->
method
(
'fetch'
)
->
will
(
$this
->
returnValue
(
array
(
'realKey'
=>
array
())));
$query
=
'SELECT * FROM foo WHERE bar = ?'
;
$params
=
array
(
666
);
$types
=
array
(
\PDO
::
PARAM_INT
);
$queryCacheProfileMock
=
$this
->
getMock
(
'Doctrine\DBAL\Cache\QueryCacheProfile'
);
$queryCacheProfileMock
->
expects
(
$this
->
any
())
->
method
(
'getResultCacheDriver'
)
->
will
(
$this
->
returnValue
(
$resultCacheDriverMock
));
// This is our main expectation
$queryCacheProfileMock
->
expects
(
$this
->
once
())
->
method
(
'generateCacheKeys'
)
->
with
(
$query
,
$params
,
$types
,
$this
->
params
)
->
will
(
$this
->
returnValue
(
array
(
'cacheKey'
,
'realKey'
)));
$conn
=
new
Connection
(
$this
->
params
,
$this
->
getMock
(
'Doctrine\DBAL\Driver'
)
);
$result
=
$conn
->
executeCacheQuery
(
$query
,
$params
,
$types
,
$queryCacheProfileMock
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Cache\ArrayStatement'
,
$result
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment