dongyin2390 2012-09-26 08:18
浏览 111
已采纳

PHPUnit - 使用缓存开/关运行所有测试两次?

I'd like to make sure my code always works as intended whether a memcached server is available or not.

Most of my functions look like this:

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;
}

Now in a TestCase I'm doing this:

class MyClassTest extends PHPUnit_Framework_TestCase {
    function testFoo()
    {
        $result = $myClass->foo($parameter);
        $this->assertSomething($result);
    }
}

I can disable caches globally during PHPUnit's setUp() like this:

class MyClassTest extends PHPUnit_Framework_TestCase {

    protected function setUp()
    {
        Cache::disable();
    }
}

After calling Cache::disable(), all calls to Cache::get() will return false during that request. Now, I want to run all tests in this class twice, once with Cache::disable(); and once without.

Any ideas on how to do that?

  • 写回答

1条回答 默认 最新

  • dqhbuwrwq692118284 2012-09-26 10:53
    关注

    One option is to create a MyClassNoCacheTest that extends from MyClassTest and just overwrite (or implement) the setUp method in MyClassNoCacheTest

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VMware安装虚拟网络驱动程序不成功,如何解决?(操作系统-linux)
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件