Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPUnit-在缓存打开/关闭的情况下运行所有测试两次?_Php_Unit Testing_Phpunit - Fatal编程技术网

PHPUnit-在缓存打开/关闭的情况下运行所有测试两次?

PHPUnit-在缓存打开/关闭的情况下运行所有测试两次?,php,unit-testing,phpunit,Php,Unit Testing,Phpunit,无论memcached服务器是否可用,我都希望确保我的代码始终按预期工作 我的大多数函数如下所示: function foo($parameter,$force = FALSE) { $result = Cache::get('foo_'.$parameter); if (empty($result) || $force) { // Do stuff with the DB... $result = "something";

无论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;
}
class MyClassTest extends PHPUnit_Framework_TestCase {

    protected function setUp()
    {
        Cache::disable();
    }
}
现在,在一个测试用例中,我正在这样做:

class MyClassTest extends PHPUnit_Framework_TestCase {
    function testFoo()
    {
        $result = $myClass->foo($parameter);
        $this->assertSomething($result);
    }
}
我可以在PHPUnit的
setUp()
过程中全局禁用缓存,如下所示:

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;
}
class MyClassTest extends PHPUnit_Framework_TestCase {

    protected function setUp()
    {
        Cache::disable();
    }
}
调用
Cache::disable()
后,在该请求期间,对
Cache::get()
的所有调用都将返回
false
。现在,我想运行这个类中的所有测试两次,一次使用
Cache::disable()和一次,不带密码


有什么办法吗?

一个选项是创建一个扩展自
MyClassTest
MyClassNoCacheTest
,只需覆盖(或实现)
MyClassNoCacheTest

中的
设置
方法,在
MyClassNoCacheTest
中,我将如何从
MyClassTest
调用每个测试方法?它将由
phpunit
处理,出于所有目的,当
MyClassNoCacheTest
扩展
MyClassTest
时,它也继承了它的所有方法(测试),因此它们将再次运行,就像您手动将它们复制到另一个文件中,然后添加了
setUp
方法一样