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
9e3c56de
Unverified
Commit
9e3c56de
authored
May 27, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored ResultCacheTest for better coverage
parent
96f8cabf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
36 deletions
+53
-36
ResultCacheTest.php
tests/Functional/ResultCacheTest.php
+53
-36
No files found.
tests/Functional/ResultCacheTest.php
View file @
9e3c56de
...
...
@@ -102,40 +102,40 @@ class ResultCacheTest extends FunctionalTestCase
$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
->
hydrate
Stmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
$data
=
$this
->
hydrate
ViaFetchAll
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchA
llA
ssociative
();
});
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
->
hydrate
Stmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchNumeric
();
$data
=
$this
->
hydrate
ViaFetchAll
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetch
All
Numeric
();
});
self
::
assertEquals
(
$numExpectedResult
,
$data
);
}
/**
* @dataProvider fetch
Mode
Provider
* @dataProvider fetchProvider
*/
public
function
test
IteratorFetch
(
callable
$fetchMode
)
:
void
public
function
test
FetchViaIteration
(
callable
$fetch
,
callable
$fetchAll
)
:
void
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$data
=
$this
->
hydrate
Stmt
(
$stmt
,
$fetchMode
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$data
=
$this
->
hydrate
ViaFetchAll
(
$stmt
,
$fetchAll
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'testcachekey'
));
$dataIterator
=
$this
->
hydrate
StmtIterator
(
$stmt
,
$fetchMode
);
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching ORDER BY test_int ASC'
,
[],
[],
new
QueryCacheProfile
(
0
,
'testcachekey'
));
$dataIterator
=
$this
->
hydrate
ViaIteration
(
$stmt
,
$fetch
);
self
::
assertEquals
(
$data
,
$dataIterator
);
}
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
=
[];
...
...
@@ -143,7 +143,7 @@ class ResultCacheTest extends FunctionalTestCase
$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
=
[];
...
...
@@ -156,14 +156,14 @@ class ResultCacheTest extends FunctionalTestCase
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
->
fetchAssociative
();
$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
->
hydrate
Stmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
$this
->
hydrate
ViaIteration
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchNumeric
();
});
...
...
@@ -173,14 +173,14 @@ class ResultCacheTest extends FunctionalTestCase
public
function
testFetchAllAndFinishSavesCache
()
:
void
{
$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
->
fetchAllAssociative
();
$stmt
->
closeCursor
();
self
::
assertCount
(
1
,
$layerCache
->
fetch
(
'testcachekey'
));
}
public
function
test
f
etchColumn
()
:
void
public
function
test
F
etchColumn
()
:
void
{
$query
=
$this
->
connection
->
getDatabasePlatform
()
->
getDummySelectSQL
(
'1'
);
...
...
@@ -201,29 +201,29 @@ class ResultCacheTest extends FunctionalTestCase
*/
private
function
assertCacheNonCacheSelectSameFetchModeAreEqual
(
array
$expectedResult
,
callable
$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
());
$data
=
$this
->
hydrate
Stmt
(
$stmt
,
$fetchMode
);
$data
=
$this
->
hydrate
ViaIteration
(
$stmt
,
$fetchMode
);
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
());
$data
=
$this
->
hydrate
Stmt
(
$stmt
,
$fetchMode
);
$data
=
$this
->
hydrate
ViaIteration
(
$stmt
,
$fetchMode
);
self
::
assertEquals
(
$expectedResult
,
$data
);
self
::
assertCount
(
1
,
$this
->
sqlLogger
->
queries
,
'just one dbal hit'
);
}
public
function
testEmptyResultCache
()
:
void
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$
data
=
$this
->
hydrateStmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
this
->
hydrateViaIteration
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
});
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$
data
=
$this
->
hydrateStmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
this
->
hydrateViaIteration
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
});
...
...
@@ -232,14 +232,15 @@ class ResultCacheTest extends FunctionalTestCase
public
function
testChangeCacheImpl
()
:
void
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
1
0
,
'emptycachekey'
));
$
data
=
$this
->
hydrateStmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
));
$
this
->
hydrateViaIteration
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
});
$secondCache
=
new
ArrayCache
();
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
10
,
'emptycachekey'
,
$secondCache
));
$data
=
$this
->
hydrateStmt
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
$stmt
=
$this
->
connection
->
executeQuery
(
'SELECT * FROM caching WHERE test_int > 500'
,
[],
[],
new
QueryCacheProfile
(
0
,
'emptycachekey'
,
$secondCache
));
$this
->
hydrateViaIteration
(
$stmt
,
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
});
...
...
@@ -250,28 +251,44 @@ class ResultCacheTest extends FunctionalTestCase
/**
* @return iterable<string,array<int,mixed>>
*/
public
static
function
fetch
Mode
Provider
()
:
iterable
public
static
function
fetchProvider
()
:
iterable
{
yield
'associative'
=>
[
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAssociative
();
},
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAllAssociative
();
},
];
yield
'numeric'
=>
[
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchNumeric
();
},
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchAllNumeric
();
},
];
yield
'column'
=>
[
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchOne
();
},
static
function
(
ResultStatement
$stmt
)
{
return
$stmt
->
fetchColumn
();
},
];
}
/**
* @return array<int, mixed>
*/
private
function
hydrate
Stmt
(
ResultStatement
$stmt
,
callable
$fetchMode
)
:
array
private
function
hydrate
ViaFetchAll
(
ResultStatement
$stmt
,
callable
$fetchAll
)
:
array
{
$data
=
[];
while
((
$row
=
$fetchMode
(
$stmt
))
!==
false
)
{
foreach
(
$fetchAll
(
$stmt
)
as
$row
)
{
$data
[]
=
is_array
(
$row
)
?
array_change_key_case
(
$row
,
CASE_LOWER
)
:
$row
;
}
...
...
@@ -283,11 +300,11 @@ class ResultCacheTest extends FunctionalTestCase
/**
* @return array<int, mixed>
*/
private
function
hydrate
StmtIterator
(
ResultStatement
$stmt
,
callable
$fetchMode
)
:
array
private
function
hydrate
ViaIteration
(
ResultStatement
$stmt
,
callable
$fetch
)
:
array
{
$data
=
[];
while
((
$row
=
$fetch
Mode
(
$stmt
))
!==
false
)
{
while
((
$row
=
$fetch
(
$stmt
))
!==
false
)
{
$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