vendredi 29 janvier 2016

PHPUnit Database DefaultTester::_construct() must implement interface error

I'm trying to set up db unit-testing for my zend-framework project using Zend Test PHPUnit, and keep running into an error when I try to instantiate a model class in the test for that model (using PHP ActiveRecord for our models).

Argument 1 passed to PHPUnit_Extensions_Database_DefaultTester::__construct() must implement interface PHPUnit_Extensions_Database_DB_IDatabaseConnection, null given

My Test Class:

require_once realpath(APPLICATION_PATH . '/models/Foo.php');

class FooTest extends Zend_Test_PHPUnit_DatabaseTestCase
{
    static protected $connection;

    protected function getConnection()
    {
        if (null == self::$connection) {
            $params = [
                'host' =>'127.0.0.1',
                'port' => '3306',
                'username' =>'user',
                'password' =>'pass',
                'dbname' =>'dbname',
            ];
            $db = Zend_Db::factory('PDO_MYSQL', $params);
            self::$connection = $this->createZendDbConnection(
                $db, 'dbname'
            );
        }
        return self::$connection;
    }

    public function testFooUpdate()
    {
        $fooTable = new Foo(); // breaks here
        ...
    }
}

I'm getting a connection to the database after the call to createZendDbConnection(), so I'm not sure why I'm getting the above error.

Aucun commentaire:

Enregistrer un commentaire