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?