How do I work with constructs in PHPUnit?

Posted by Ben Dauphinee on Stack Overflow See other posts from Stack Overflow or by Ben Dauphinee
Published on 2010-05-30T02:13:47Z Indexed on 2010/05/30 2:32 UTC
Read the original article Hit count: 296

Filed under:
|
|

I am new into PHPUnit, and just digging through the manual. I cannot find a decent example of how to build a complete test from end to end though, and so, am left with questions.

One of these is how can I prep my environment to properly test my code?

I am trying to figure out how to properly pass various configuration values needed for both the test setup/teardown methods, and the configs for the class itself.

// How can I set these variables on testing start?
protected $_db = null;
protected $_config = null;

// So that this function runs properly?
public function setUp(){
    $this->_acl = new acl(
        $this->_db,    // The database connection for the class passed 
                       // from whatever test construct

        $this->_config // Config values passed in from construct
    );
}

// Can I just drop in a construct like this, and have it work properly?
// And if so, how can I set the construct call properly?
public function __construct(
    Zend_Db_Adapter_Abstract $db, $config = array(),
    $baselinedatabase = NULL, $databaseteardown = NULL
){
    $this->_db = $db;
    $this->_config = $config;
    $this->_baselinedatabase = $baselinedatabase;
    $this->_databaseteardown = $databaseteardown;
}

// Or is the wrong idea to be pursuing?

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about php5