PHPUnit - Running all tests twice with on / off cache?

I would like to make sure that my code always works as intended, whether the memcached server is accessible 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 TestCase I do this:

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

I can disable caches globally during PHPUnit setUp() as follows:

 class MyClassTest extends PHPUnit_Framework_TestCase { protected function setUp() { Cache::disable(); } } 

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

Any ideas on how to do this?

+4
source share
1 answer

One option is to create a MyClassNoCacheTest , which extends from MyClassTest and simply overwrites (or implements) the setUp method in MyClassNoCacheTest

+8
source

Source: https://habr.com/ru/post/1436318/


All Articles