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
a60be246
Commit
a60be246
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 tests for Cache\QueryCacheProfile
parent
99629012
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
QueryCacheProfileTest.php
tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
+78
-0
No files found.
tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
0 → 100644
View file @
a60be246
<?php
namespace
Doctrine\Tests\DBAL\Cache
;
require_once
__DIR__
.
'/../../TestInit.php'
;
use
Doctrine\DBAL\Cache\QueryCacheProfile
;
use
Doctrine\Tests\DbalTestCase
;
class
QueryCacheProfileTest
extends
DbalTestCase
{
const
LIFETIME
=
3600
;
const
CACHE_KEY
=
'user_specified_cache_key'
;
/** @var QueryCacheProfile */
private
$queryCacheProfile
;
protected
function
setUp
()
{
$this
->
queryCacheProfile
=
new
QueryCacheProfile
(
self
::
LIFETIME
,
self
::
CACHE_KEY
);
}
/**
* @test
*/
public
function
it_should_use_the_given_cache_key_if_present
()
{
$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'
);
$expectedRealCacheKey
=
'query=SELECT * FROM foo WHERE bar = ?¶ms=a:1:{i:0;i:666;}&types=a:1:{i:0;'
.
'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";}'
;
$cacheKeysResult
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$this
->
assertEquals
(
self
::
CACHE_KEY
,
$cacheKeysResult
[
0
],
'The returned cached key should match the given one'
);
$this
->
assertEquals
(
$expectedRealCacheKey
,
$cacheKeysResult
[
1
]);
}
/**
* @test
*/
public
function
it_should_generate_an_automatic_key_if_no_key_has_been_specified
()
{
$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'
);
$expectedRealCacheKey
=
'query=SELECT * FROM foo WHERE bar = ?¶ms=a:1:{i:0;i:666;}&types=a:1:{i:0;'
.
'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";}'
;
$this
->
queryCacheProfile
=
$this
->
queryCacheProfile
->
setCacheKey
(
null
);
$cacheKeysResult
=
$this
->
queryCacheProfile
->
generateCacheKeys
(
$query
,
$params
,
$types
,
$connectionParams
);
$this
->
assertEquals
(
'8f74136f51719d57f4da9b6d2ba955b42189bb81'
,
$cacheKeysResult
[
0
]);
$this
->
assertEquals
(
$expectedRealCacheKey
,
$cacheKeysResult
[
1
]);
}
}
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