Reputation: 1532
I'm just getting into writing testcases and am not sure how to handle certain tests. The classes I'm testing are, in very basic terms, wrappers for various opcode caches. The tests will be bundled into software that will be downloaded and used on many different hosts, thus I'm perplexed as to how to handle testing these classes for two reasons.
Take for example this apc wrapper
class Storage_Container_Apc extends Storage_Container implements Storage_iContainer
{
protected $_id_prefix = '';
protected $_file_prefix = '';
function __construct($id_prefix='', $file_prefix='', $options=array())
{
$this->_id_prefix = $id_prefix;
$this->_file_prefix = $file_prefix;
}
/**
* @see Storage_iContainer::available
*/
public static function available()
{
return extension_loaded('apc') && ini_get('apc.enabled');
}
}
And this basic testcase.
class StorageContainerApcTest extends \PHPUnit_Framework_TestCase
{
public function testAvailability()
{
$this->assertTrue(Storage_Container_Apc::available());
}
}
On systems without APC this test will obviously fail, however it's not really a failure of course because the class is module dependent and not used if it is not available on the system. So for this point what should the test actually be, so that it returns ok. Would it be something like this?
class StorageContainerApcTest extends \PHPUnit_Framework_TestCase
{
public function testAvailability()
{
if(extension_loaded('apc') && ini_get('apc.enabled'))
{
$this->assertTrue(Storage_Container_Apc::available());
}
else
{
$this->assertFalse(Storage_Container_Apc::available());
}
}
}
My last question involves how to test these opcode wrappers with tests. As it is impossible to run more than one opcode at any given time?
Many thanks for any pointers.
Upvotes: 0
Views: 824
Reputation: 3381
Also you can use
@codeCoverageIgnore
For example:
/**
* @see Storage_iContainer::available
* @codeCoverageIgnore
*/
public static function available()
{
return extension_loaded('apc') && ini_get('apc.enabled');
}
Upvotes: 0
Reputation: 1532
I've realised I should be using
protected function setUp() {
if (!(extension_loaded('apc') && ini_get('apc.enabled'))) {
$this->markTestSkipped('The APC extension is not available.');
}
}
Upvotes: 1