views:

217

answers:

0

I'm having 'fun' testing interactions in a CodeIgniter based web app.

It seems when running the entire test suite "phpunit AllTests.php" it loads all of the test classes, their targets (Systems under Test) and creates a PHPUnit_Framework_TestSuite instance which presumably iterates over the classes which extend CIUnit_TestCase and runs them.

The problem comes where you have multiple classes referencing another class (such as a library). As all the classes are loaded into the same process space, PHP reports "cannot redefine class xyz". Have I missed something here or doing something haenously wrong?

In my test class i'm doing something like:

include_once dirname(__FILE__).'/../CIUnit.php';
include_once dirname(__FILE__).'/../../libraries/ProductsService.php';


class testProductsService extends CIUnit_TestCase {

    public function testGetProducts_ReturnsArrayOfProducts(){
     $service = new ProductsService();
     $products = $service->getProducts();

   $this->assertTrue(is_array($products));
    }
}

The problem manifests as I have a controller which does:

$this->load->library('ProductsService');