Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
apc
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
apc
Commits
89780810
Verified
Commit
89780810
authored
6 months ago
by
Alberto Paderno
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3464217
: Merge ApcCacheGetMultipleUnitTest into ApcCacheSaveCase and rename the latter
parent
9c1f7aa8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!45
Issue #3464217: Merge ApcCacheGetMultipleUnitTest into ApcCacheSaveCase and rename the latter
Pipeline
#236360
passed
6 months ago
Stage: build
Stage: validate
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/apc.test
+72
-44
72 additions, 44 deletions
tests/apc.test
with
72 additions
and
44 deletions
tests/apc.test
+
72
−
44
View file @
89780810
...
...
@@ -131,12 +131,67 @@ class ApcCacheTestCase extends DrupalWebTestCase {
$this
->
assertFalse
(
cache_get
(
$cid
,
$bin
),
$message
);
}
/**
* Asserts two or more cache items exist.
*
* @param string $bin
* The cache bin.
* @param array $cids
* An array containing the cache IDs to retrieve.
* @param array $values
* An array whose keys are cache IDs and whose values are the expected
* values. If a value is irrelevant, use NULL.
*/
protected
function
assertCacheItems
(
$bin
,
$cids
,
$values
)
{
$items
=
cache_get_multiple
(
$cids
,
$bin
);
foreach
(
$values
as
$cid
=>
$value
)
{
$this
->
assertTrue
(
isset
(
$items
[
$cid
]),
t
(
'@cache_id was found in the cache.'
,
array
(
'@cache_id'
=>
$cid
))
);
$this
->
assertTrue
(
is_object
(
$items
[
$cid
])
&&
isset
(
$items
[
$cid
]
->
data
),
t
(
'@cache_id was correctly stored in the cache.'
,
array
(
'@cache_id'
=>
$cid
)));
if
(
!
is_null
(
$value
)
&&
is_object
(
$items
[
$cid
])
&&
isset
(
$items
[
$cid
]
->
data
))
{
$this
->
assertIdentical
(
$items
[
$cid
]
->
data
,
$value
,
t
(
'@cache_id was correctly stored in the cache.'
,
array
(
'@cache_id'
=>
$cid
))
);
}
}
}
/**
* Asserts two or more cache items do not exist.
*
* @param string $bin
* The cache bin.
* @param array $cids
* An array containing the cache IDs to retrieve.
* @param array $non_existent_cids
* An array containing the cache IDs that should not exist.
*/
protected
function
assertNoCacheItems
(
$bin
,
$cids
,
$non_existent_cids
)
{
$items
=
cache_get_multiple
(
$cids
,
$bin
);
foreach
(
$non_existent_cids
as
$cid
)
{
$this
->
assertFalse
(
isset
(
$items
[
$cid
]),
t
(
'@cache_id was not found in the cache.'
,
array
(
'@cache_id'
=>
$cid
))
);
}
}
}
/**
* Tests saving and retrieving data.
*/
class
ApcCacheSaveCase
extends
ApcCacheTestCase
{
class
ApcCacheSave
AndRetrieve
Case
extends
ApcCacheTestCase
{
/**
* {@inheritdoc}
...
...
@@ -144,7 +199,7 @@ class ApcCacheSaveCase extends ApcCacheTestCase {
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Save cache test'
,
'description'
=>
'Verifies the cached items are correctly s
tored
.'
,
'description'
=>
'Verifies the cached items are correctly s
aved and the retrieved values are correct
.'
,
'group'
=>
'Alternative PHP Cache'
,
);
}
...
...
@@ -152,7 +207,7 @@ class ApcCacheSaveCase extends ApcCacheTestCase {
/**
* Tests retrieving data.
*/
protected
function
testRetriev
ing
Data
()
{
protected
function
testRetriev
e
Data
()
{
$bin
=
'cache_apc'
;
$values
=
array
(
'boolean'
=>
TRUE
,
...
...
@@ -184,52 +239,25 @@ class ApcCacheSaveCase extends ApcCacheTestCase {
}
}
}
/**
* Tests cache_get_multiple().
*/
class
ApcCacheGetMultipleUnitTest
extends
ApcCacheTestCase
{
/**
* {@inheritdoc}
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Fetch multiple cache items'
,
'description'
=>
'Verifies that multiple values are retrieved correctly.'
,
'group'
=>
'Alternative PHP Cache'
,
);
}
/**
* Tests cache_get_multiple().
*/
public
function
test
Cach
eMultiple
()
{
public
function
test
Retriev
eMultiple
Value
()
{
$bin
=
'cache_apc'
;
$cids
=
array
(
$this
->
randomName
(
16
)
=>
$this
->
randomString
(
10
),
$this
->
randomName
(
16
)
=>
$this
->
randomString
(
10
),
);
foreach
(
$cids
as
$cid
=>
$value
)
{
cache_set
(
$cid
,
$value
,
$bin
);
}
$this
->
assertCacheItems
(
$bin
,
$cids
);
$item1
=
$this
->
randomName
(
10
);
$item2
=
$this
->
randomName
(
10
);
cache_set
(
'item1'
,
$item1
,
$bin
);
cache_set
(
'item2'
,
$item2
,
$bin
);
$this
->
assertCacheItem
(
$bin
,
'item1'
,
$item1
);
$this
->
assertCacheItem
(
$bin
,
'item2'
,
$item2
);
// Fetch both records from the database with cache_get_multiple().
$item_ids
=
array
(
'item1'
,
'item2'
);
$items
=
cache_get_multiple
(
$item_ids
,
$bin
);
$this
->
assertEqual
(
$items
[
'item1'
]
->
data
,
$item1
,
t
(
'Item1 was correctly stored in the cache.'
));
$this
->
assertEqual
(
$items
[
'item2'
]
->
data
,
$item2
,
t
(
'Item2 was correctly stored in the cache.'
));
// Remove one item from the cache.
cache_clear_all
(
'item2'
,
$bin
);
// Confirm that only one item is returned by cache_get_multiple().
$item_ids
=
array
(
'item1'
,
'item2'
);
$items
=
cache_get_multiple
(
$item_ids
,
$bin
);
$this
->
assertEqual
(
$items
[
'item1'
]
->
data
,
$item1
,
t
(
'Item1 was correctly stored in the cache.'
));
$this
->
assertFalse
(
isset
(
$items
[
'item2'
]),
t
(
'Item2 was not present in the cache.'
));
$this
->
assertTrue
(
count
(
$items
)
==
1
,
t
(
'Only an entry was retrieved from the cache.'
));
$cids
=
array_keys
(
$cids
);
cache_clear_all
(
$cids
[
1
],
$bin
);
$this
->
assertNoCacheItems
(
$bin
,
$cids
,
array
(
$cids
[
1
],
'item3'
));
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment