Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
e2513de6
Commit
e2513de6
authored
May 11, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better testing: time()-function-mock
as discussed in #203
https://github.com/yiisoft/yii2/issues/203#issuecomment-17759631
parent
c4e9e003
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
CacheTest.php
tests/unit/framework/caching/CacheTest.php
+23
-0
DbCacheTest.php
tests/unit/framework/caching/DbCacheTest.php
+13
-0
FileCacheTest.php
tests/unit/framework/caching/FileCacheTest.php
+11
-0
No files found.
tests/unit/framework/caching/CacheTest.php
View file @
e2513de6
<?php
namespace
yii\caching
;
/**
* Mock for the time() function for caching classes
* @return int
*/
function
time
()
{
return
\yiiunit\framework\caching\CacheTest
::
$time
?:
\time
();
}
namespace
yiiunit\framework\caching
;
use
yiiunit\TestCase
;
use
yii\caching\Cache
;
...
...
@@ -9,6 +21,12 @@ use yii\caching\Cache;
abstract
class
CacheTest
extends
TestCase
{
/**
* @var int virtual time to be returned by mocked time() function.
* Null means normal time() behavior.
*/
public
static
$time
;
/**
* @return Cache
*/
abstract
protected
function
getCacheInstance
();
...
...
@@ -19,6 +37,11 @@ abstract class CacheTest extends TestCase
$this
->
mockApplication
();
}
protected
function
tearDown
()
{
static
::
$time
=
null
;
}
/**
* @return Cache
*/
...
...
tests/unit/framework/caching/DbCacheTest.php
View file @
e2513de6
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\DbCache
;
use
yiiunit\TestCase
;
...
...
@@ -70,4 +72,15 @@ class DbCacheTest extends CacheTest
}
return
$this
->
_cacheInstance
;
}
public
function
testExpire
()
{
$cache
=
$this
->
getCacheInstance
();
$this
->
assertTrue
(
$cache
->
set
(
'expire_test'
,
'expire_test'
,
2
));
static
::
$time
=
time
()
+
1
;
$this
->
assertEquals
(
'expire_test'
,
$cache
->
get
(
'expire_test'
));
static
::
$time
=
time
()
+
2
;
$this
->
assertFalse
(
$cache
->
get
(
'expire_test'
));
}
}
tests/unit/framework/caching/FileCacheTest.php
View file @
e2513de6
...
...
@@ -22,4 +22,15 @@ class FileCacheTest extends CacheTest
}
return
$this
->
_cacheInstance
;
}
public
function
testExpire
()
{
$cache
=
$this
->
getCacheInstance
();
$this
->
assertTrue
(
$cache
->
set
(
'expire_test'
,
'expire_test'
,
2
));
static
::
$time
=
time
()
+
1
;
$this
->
assertEquals
(
'expire_test'
,
$cache
->
get
(
'expire_test'
));
static
::
$time
=
time
()
+
2
;
$this
->
assertFalse
(
$cache
->
get
(
'expire_test'
));
}
}
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