views:

90

answers:

2

I have a class that uses a lot of database internally, so I built the constructor with a $db handle that I am supposed to pass to it.

I am just getting started with PHPUnit, and I am not sure how I should go ahead and pass the database handle through setup.

// Test code
public function setUp(/*do I pass a database handle through here, using a reference? aka &$db*/){
    $this->_acl = new acl;
}

// Construct from acl class
public function __construct(Zend_Db_Adapter_Abstract $db, $config = array()){
+1  A: 

You can do normally without reference same as constructor because this method is simplest.

Svisstack
@Svisstack Do you mean that I should use the same code in my setUp function as I do in my class construct?
Ben Dauphinee
@Ben Dauphinee: Sorry i miss understand your question. You can do normally without reference same as constructor because this method is simplest. You really must use reference for this?
Svisstack
+1  A: 

You would do it like this:

public class TestMyACL extends PHPUnit_Framework_TestCase {

    protected $adapter;
    protected $config;
    protected $myACL;

    protected function setUp() {
        $this->adapter  = // however you create a new ZendDbADapter
        $this->config   = // however you create a new config array
        $this->myACL    = new ACL($this->adapter, $this->config); // This is the System  Under Test (SUT)
    }

}

IMHO, you need to work on your naming conventions. See Zend Framework Naming Conventions, for a start. An example would be the underscore, look up variables in the link. Also class naming.

Gutzofter