Dur*_*sun 4 php phpunit unit-testing
无论memcached服务器是否可用,我都希望确保我的代码始终按预期工作.
我的大多数功能看起来像这样:
function foo($parameter,$force = FALSE)
{
$result = Cache::get('foo_'.$parameter);
if (empty($result) || $force)
{
// Do stuff with the DB...
$result = "something";
Cache::put('foo_'.$parameter,$result,$timeout);
}
return $result;
}
Run Code Online (Sandbox Code Playgroud)
现在在TestCase中,我这样做:
class MyClassTest extends PHPUnit_Framework_TestCase {
function testFoo()
{
$result = $myClass->foo($parameter);
$this->assertSomething($result);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在PHPUnit中全局禁用缓存,setUp()如下所示:
class MyClassTest extends PHPUnit_Framework_TestCase {
protected function setUp()
{
Cache::disable();
}
}
Run Code Online (Sandbox Code Playgroud)
在呼叫之后Cache::disable(),所有呼叫Cache::get()将false在该请求期间返回.现在,我想在这个类中运行两次所有测试,一次使用Cache::disable();,一次不使用.
有关如何做到这一点的任何想法?
| 归档时间: |
|
| 查看次数: |
3204 次 |
| 最近记录: |