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
3eb6f0a2
Unverified
Commit
3eb6f0a2
authored
May 27, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored ResultCacheTest for better coverage
parent
4af4999b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
ResultCacheTest.php
tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
+22
-20
No files found.
tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
View file @
3eb6f0a2
...
@@ -102,13 +102,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -102,13 +102,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
$numExpectedResult
[]
=
array_values
(
$v
);
$numExpectedResult
[]
=
array_values
(
$v
);
}
}
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
ASSOCIATIVE
);
$data
=
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
ASSOCIATIVE
);
self
::
assertEquals
(
$this
->
expectedResult
,
$data
);
self
::
assertEquals
(
$this
->
expectedResult
,
$data
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
NUMERIC
);
$data
=
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
NUMERIC
);
...
@@ -124,10 +124,10 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -124,10 +124,10 @@ class ResultCacheTest extends DbalFunctionalTestCase
private
function
assertStandardAndIteratorFetchAreEqual
(
int
$fetchMode
)
:
void
private
function
assertStandardAndIteratorFetchAreEqual
(
int
$fetchMode
)
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$dataIterator
=
$this
->
hydrateStmtIterator
(
$stmt
,
$fetchMode
);
$dataIterator
=
$this
->
hydrateStmtIterator
(
$stmt
,
$fetchMode
);
self
::
assertEquals
(
$data
,
$dataIterator
);
self
::
assertEquals
(
$data
,
$dataIterator
);
...
@@ -135,7 +135,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -135,7 +135,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
public
function
testDontCloseNoCache
()
:
void
public
function
testDontCloseNoCache
()
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
[];
$data
=
[];
...
@@ -143,7 +143,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -143,7 +143,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
$data
[]
=
$row
;
$data
[]
=
$row
;
}
}
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
[];
$data
=
[];
...
@@ -156,12 +156,12 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -156,12 +156,12 @@ class ResultCacheTest extends DbalFunctionalTestCase
public
function
testDontFinishNoCache
()
:
void
public
function
testDontFinishNoCache
()
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$stmt
->
fetch
(
FetchMode
::
ASSOCIATIVE
);
$stmt
->
fetch
(
FetchMode
::
ASSOCIATIVE
);
$stmt
->
closeCursor
();
$stmt
->
closeCursor
();
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
NUMERIC
);
$this
->
hydrateStmt
(
$stmt
,
FetchMode
::
NUMERIC
);
...
@@ -171,7 +171,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -171,7 +171,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
public
function
testFetchAllAndFinishSavesCache
()
:
void
public
function
testFetchAllAndFinishSavesCache
()
:
void
{
{
$layerCache
=
new
ArrayCache
();
$layerCache
=
new
ArrayCache
();
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
,
$layerCache
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
,
$layerCache
));
$stmt
->
fetchAll
();
$stmt
->
fetchAll
();
$stmt
->
closeCursor
();
$stmt
->
closeCursor
();
...
@@ -199,13 +199,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -199,13 +199,13 @@ class ResultCacheTest extends DbalFunctionalTestCase
*/
*/
private
function
assertCacheNonCacheSelectSameFetchModeAreEqual
(
array
$expectedResult
,
int
$fetchMode
)
:
void
private
function
assertCacheNonCacheSelectSameFetchModeAreEqual
(
array
$expectedResult
,
int
$fetchMode
)
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
self
::
assertEquals
(
2
,
$stmt
->
columnCount
());
self
::
assertEquals
(
2
,
$stmt
->
columnCount
());
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
self
::
assertEquals
(
$expectedResult
,
$data
);
self
::
assertEquals
(
$expectedResult
,
$data
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
self
::
assertEquals
(
2
,
$stmt
->
columnCount
());
self
::
assertEquals
(
2
,
$stmt
->
columnCount
());
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchMode
);
...
@@ -215,23 +215,24 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -215,23 +215,24 @@ class ResultCacheTest extends DbalFunctionalTestCase
public
function
testEmptyResultCache
()
:
void
public
function
testEmptyResultCache
()
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
data
=
$
this
->
hydrateStmt
(
$stmt
);
$this
->
hydrateStmt
(
$stmt
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
data
=
$
this
->
hydrateStmt
(
$stmt
);
$this
->
hydrateStmt
(
$stmt
);
self
::
assertCount
(
1
,
$this
->
sqlLogger
->
queries
,
'just one dbal hit'
);
self
::
assertCount
(
1
,
$this
->
sqlLogger
->
queries
,
'just one dbal hit'
);
}
}
public
function
testChangeCacheImpl
()
:
void
public
function
testChangeCacheImpl
()
:
void
{
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
data
=
$
this
->
hydrateStmt
(
$stmt
);
$this
->
hydrateStmt
(
$stmt
);
$secondCache
=
new
ArrayCache
();
$secondCache
=
new
ArrayCache
();
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
10
,
'emptycachekey'
,
$secondCache
));
$data
=
$this
->
hydrateStmt
(
$stmt
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
,
$secondCache
));
$this
->
hydrateStmt
(
$stmt
);
self
::
assertCount
(
2
,
$this
->
sqlLogger
->
queries
,
'two hits'
);
self
::
assertCount
(
2
,
$this
->
sqlLogger
->
queries
,
'two hits'
);
self
::
assertCount
(
1
,
$secondCache
->
fetch
(
'emptycachekey'
));
self
::
assertCount
(
1
,
$secondCache
->
fetch
(
'emptycachekey'
));
...
@@ -243,7 +244,8 @@ class ResultCacheTest extends DbalFunctionalTestCase
...
@@ -243,7 +244,8 @@ class ResultCacheTest extends DbalFunctionalTestCase
private
function
hydrateStmt
(
ResultStatement
$stmt
,
int
$fetchMode
=
FetchMode
::
ASSOCIATIVE
)
:
array
private
function
hydrateStmt
(
ResultStatement
$stmt
,
int
$fetchMode
=
FetchMode
::
ASSOCIATIVE
)
:
array
{
{
$data
=
[];
$data
=
[];
while
(
$row
=
$stmt
->
fetch
(
$fetchMode
))
{
foreach
(
$stmt
->
fetchAll
(
$fetchMode
)
as
$row
)
{
$data
[]
=
is_array
(
$row
)
?
array_change_key_case
(
$row
,
CASE_LOWER
)
:
$row
;
$data
[]
=
is_array
(
$row
)
?
array_change_key_case
(
$row
,
CASE_LOWER
)
:
$row
;
}
}
...
...
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