Unit Testing Codeigniter Classes with fooStack - clashes

Posted by DrPep on Stack Overflow See other posts from Stack Overflow or by DrPep
Published on 2010-03-31T09:58:18Z Indexed on 2010/03/31 10:03 UTC
Read the original article Hit count: 438

Filed under:
|
|
|

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');

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about php