Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
夏彬
yii2bootstrap
Commits
64fb2a81
Commit
64fb2a81
authored
Feb 07, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests for cache
parent
81188003
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
348 additions
and
2 deletions
+348
-2
DbCache.php
framework/caching/DbCache.php
+2
-2
.gitignore
tests/unit/.gitignore
+1
-0
ApcCacheTest.php
tests/unit/framework/caching/ApcCacheTest.php
+27
-0
CacheTest.php
tests/unit/framework/caching/CacheTest.php
+82
-0
DbCacheTest.php
tests/unit/framework/caching/DbCacheTest.php
+70
-0
FileCacheTest.php
tests/unit/framework/caching/FileCacheTest.php
+25
-0
MemCacheTest.php
tests/unit/framework/caching/MemCacheTest.php
+27
-0
MemCachedTest.php
tests/unit/framework/caching/MemCachedTest.php
+29
-0
WinCacheTest.php
tests/unit/framework/caching/WinCacheTest.php
+31
-0
XCacheTest.php
tests/unit/framework/caching/XCacheTest.php
+27
-0
ZendDataCacheTest.php
tests/unit/framework/caching/ZendDataCacheTest.php
+27
-0
No files found.
framework/caching/DbCache.php
View file @
64fb2a81
...
...
@@ -104,7 +104,7 @@ class DbCache extends Cache
$query
=
new
Query
;
$query
->
select
(
array
(
'data'
))
->
from
(
$this
->
cacheTableName
)
->
where
(
'id = :id AND (expire = 0 OR expire >
:time)'
,
array
(
':id'
=>
$key
,
':time'
=>
time
()
));
->
where
(
'id = :id AND (expire = 0 OR expire >
'
.
time
()
.
')'
,
array
(
':id'
=>
$key
));
$db
=
$this
->
getDb
();
if
(
$db
->
enableQueryCache
)
{
// temporarily disable and re-enable query caching
...
...
@@ -131,7 +131,7 @@ class DbCache extends Cache
$query
->
select
(
array
(
'id'
,
'data'
))
->
from
(
$this
->
cacheTableName
)
->
where
(
array
(
'id'
=>
$keys
))
->
andWhere
(
"expire = 0 OR expire > "
.
time
()
.
")"
);
->
andWhere
(
'(expire = 0 OR expire > '
.
time
()
.
')'
);
$db
=
$this
->
getDb
();
if
(
$db
->
enableQueryCache
)
{
...
...
tests/unit/.gitignore
0 → 100644
View file @
64fb2a81
runtime/cache/*
\ No newline at end of file
tests/unit/framework/caching/ApcCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\ApcCache
;
use
yiiunit\TestCase
;
/**
* Class for testing APC cache backend
*/
class
ApcCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return ApcCache
*/
protected
function
getCacheInstance
()
{
if
(
!
extension_loaded
(
"apc"
))
{
$this
->
markTestSkipped
(
"APC not installed. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
ApcCache
();
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/CacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yiiunit\TestCase
;
use
yii\caching\Cache
;
/**
* Base class for testing cache backends
*/
abstract
class
CacheTest
extends
TestCase
{
/**
* @return Cache
*/
abstract
protected
function
getCacheInstance
();
public
function
testSet
()
{
$cache
=
$this
->
getCacheInstance
();
$cache
->
set
(
'string_test'
,
'string_test'
);
$cache
->
set
(
'number_test'
,
42
);
$cache
->
set
(
'array_test'
,
array
(
'array_test'
=>
'array_test'
));
$cache
[
'arrayaccess_test'
]
=
new
\stdClass
();
}
public
function
testGet
()
{
$cache
=
$this
->
getCacheInstance
();
$this
->
assertEquals
(
'string_test'
,
$cache
->
get
(
'string_test'
));
$this
->
assertEquals
(
42
,
$cache
->
get
(
'number_test'
));
$array
=
$cache
->
get
(
'array_test'
);
$this
->
assertArrayHasKey
(
'array_test'
,
$array
);
$this
->
assertEquals
(
'array_test'
,
$array
[
'array_test'
]);
$this
->
assertInstanceOf
(
'stdClass'
,
$cache
[
'arrayaccess_test'
]);
}
public
function
testMget
()
{
$cache
=
$this
->
getCacheInstance
();
$this
->
assertEquals
(
array
(
'string_test'
=>
'string_test'
,
'number_test'
=>
42
),
$cache
->
mget
(
array
(
'string_test'
,
'number_test'
)));
}
public
function
testExpire
()
{
$cache
=
$this
->
getCacheInstance
();
$cache
->
set
(
'expire_test'
,
'expire_test'
,
2
);
sleep
(
1
);
$this
->
assertEquals
(
'expire_test'
,
$cache
->
get
(
'expire_test'
));
sleep
(
2
);
$this
->
assertEquals
(
false
,
$cache
->
get
(
'expire_test'
));
}
public
function
testAdd
()
{
$cache
=
$this
->
getCacheInstance
();
// should not change existing keys
$cache
->
add
(
'number_test'
,
13
);
$this
->
assertEquals
(
42
,
$cache
->
get
(
'number_test'
));
// should store data is it's not there yet
$cache
->
add
(
'add_test'
,
13
);
$this
->
assertEquals
(
13
,
$cache
->
get
(
'add_test'
));
}
public
function
testDelete
()
{
$cache
=
$this
->
getCacheInstance
();
$cache
->
delete
(
'number_test'
);
$this
->
assertEquals
(
null
,
$cache
->
get
(
'number_test'
));
}
public
function
testFlush
()
{
$cache
=
$this
->
getCacheInstance
();
$cache
->
flush
();
$this
->
assertEquals
(
null
,
$cache
->
get
(
'add_test'
));
}
}
tests/unit/framework/caching/DbCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\DbCache
;
use
yiiunit\TestCase
;
/**
* Class for testing file cache backend
*/
class
DbCacheTest
extends
CacheTest
{
private
$_cacheInstance
;
private
$_connection
;
function
__construct
()
{
if
(
!
extension_loaded
(
'pdo'
)
||
!
extension_loaded
(
'pdo_mysql'
))
{
$this
->
markTestSkipped
(
'pdo and pdo_mysql extensions are required.'
);
}
$this
->
getConnection
()
->
createCommand
(
"
CREATE TABLE IF NOT EXISTS tbl_cache (
id char(128) NOT NULL,
expire int(11) DEFAULT NULL,
data LONGBLOB,
PRIMARY KEY (id),
KEY expire (expire)
);
"
)
->
execute
();
}
/**
* @param bool $reset whether to clean up the test database
* @return \yii\db\Connection
*/
function
getConnection
(
$reset
=
true
)
{
if
(
$this
->
_connection
===
null
)
{
$params
=
$this
->
getParam
(
'mysql'
);
$db
=
new
\yii\db\Connection
;
$db
->
dsn
=
$params
[
'dsn'
];
$db
->
username
=
$params
[
'username'
];
$db
->
password
=
$params
[
'password'
];
if
(
$reset
)
{
$db
->
open
();
$lines
=
explode
(
';'
,
file_get_contents
(
$params
[
'fixture'
]));
foreach
(
$lines
as
$line
)
{
if
(
trim
(
$line
)
!==
''
)
{
$db
->
pdo
->
exec
(
$line
);
}
}
}
$this
->
_connection
=
$db
;
}
return
$this
->
_connection
;
}
/**
* @return DbCache
*/
protected
function
getCacheInstance
()
{
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
DbCache
(
array
(
'db'
=>
$this
->
getConnection
(),
));
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/FileCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\FileCache
;
use
yiiunit\TestCase
;
/**
* Class for testing file cache backend
*/
class
FileCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return FileCache
*/
protected
function
getCacheInstance
()
{
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
FileCache
(
array
(
'cachePath'
=>
'@yiiunit/runtime/cache'
,
));
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/MemCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\MemCache
;
use
yiiunit\TestCase
;
/**
* Class for testing memcache cache backend
*/
class
MemCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return MemCache
*/
protected
function
getCacheInstance
()
{
if
(
!
extension_loaded
(
"memcache"
))
{
$this
->
markTestSkipped
(
"memcache not installed. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
MemCache
();
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/MemCachedTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\MemCache
;
use
yiiunit\TestCase
;
/**
* Class for testing memcache cache backend
*/
class
MemCachedTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return MemCache
*/
protected
function
getCacheInstance
()
{
if
(
!
extension_loaded
(
"memcached"
))
{
$this
->
markTestSkipped
(
"memcached not installed. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
MemCache
(
array
(
'useMemcached'
=>
true
,
));
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/WinCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\FileCache
;
use
yiiunit\TestCase
;
/**
* Class for testing wincache backend
*/
class
WinCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return WinCache
*/
protected
function
getCacheInstance
()
{
if
(
!
extension_loaded
(
'wincache'
))
{
$this
->
markTestSkipped
(
"Wincache not installed. Skipping."
);
}
if
(
!
ini_get
(
'wincache.ucenabled'
))
{
$this
->
markTestSkipped
(
"Wincache user cache disabled. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
WinCache
();
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/XCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\XCache
;
use
yiiunit\TestCase
;
/**
* Class for testing xcache backend
*/
class
XCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return XCache
*/
protected
function
getCacheInstance
()
{
if
(
!
function_exists
(
"xcache_isset"
))
{
$this
->
markTestSkipped
(
"XCache not installed. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
XCache
();
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
tests/unit/framework/caching/ZendDataCacheTest.php
0 → 100644
View file @
64fb2a81
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\ZendDataCache
;
use
yiiunit\TestCase
;
/**
* Class for testing Zend cache backend
*/
class
ZendDataCacheTest
extends
CacheTest
{
private
$_cacheInstance
=
null
;
/**
* @return ZendDataCache
*/
protected
function
getCacheInstance
()
{
if
(
!
function_exists
(
"zend_shm_cache_store"
))
{
$this
->
markTestSkipped
(
"Zend Data cache not installed. Skipping."
);
}
if
(
$this
->
_cacheInstance
===
null
)
{
$this
->
_cacheInstance
=
new
ZendDataCache
();
}
return
$this
->
_cacheInstance
;
}
}
\ No newline at end of file
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