1

I'm trying to get started with setting up unit tests using a MySQL database and I'm running into this exception:

DBTest::test__getException()

Argument 1 passed to PHPUnit_Extensions_Database_DataSet_DefaultTableIterator::__construct() must be an array, null given.

I don't know what I could be missing

My Unit Test Code:

<?php
class DBTest extends Generic_Tests_DatabaseTestCase {
    //...
    public function getDataSet() {
        $dataSet = $this->createMySQLXMLDataSet(dirname(__FILE__)."/../db/t_enroll_fixtures.xml");
        return $dataSet;
    }

    public function setUp() {
        $this->X = $this->getMock('\X\Engine\X');
        $this->model = new Model($this->X, 't_users');
        $this->className = get_class($this->model);
        parent::setUp();
    }

    public function tearDown() {
        $this->X = NULL;
        $this->model = NULL;
        parent::tearDown();
    }

    public function testMagicFields() {
        $this->getConnection()->addTable('t_enroll');
        $this->assertEquals(10, $this->getConnection()->getRowCount('t_enroll'));
    }
}
?>

The Generic_Test_DatabaseTestCase Class:

<?php
require_once "PHPUnit/Extensions/Database/TestCase.php";
abstract class Generic_Tests_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase {

    // only instantiate pdo once for test clean-up/fixture load
    static private $pdo = null;
    // only instantiate PHPUnit_Extensions_Database_DB_IDatabaseConnection once per test
    private $conn = null;

    final public function getConnection() {
        if($this->conn === null) {
            if(self::$pdo == null) {
                self::$pdo = new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']);
            }
            $this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
        }

        return $this->conn;
    }

}
?>

What am I missing?

3
  • Related Question: stackoverflow.com/questions/4640802/… Commented Mar 1, 2012 at 15:09
  • @cillosis This question is spot-on regarding the error message I'm receiving, but the solution for the OP appears to be very Zend-specific. Could you perhaps shed some more light on how I could use this question to help me? Commented Mar 1, 2012 at 15:20
  • @LeviHackwith I am having the same issue, and not using Zend. I already have the database name in my xml document. Did you come up with a different solution, or did that fix it for you? Thanks. Commented Mar 24, 2015 at 16:16

2 Answers 2

2

I had the same problem. The reason was, that the XML fixture was generated by MySQLDump and someone removed the <database name="xyz"> node. This turned $this->tables in PHPUnit into NULL instead Array

Sign up to request clarification or add additional context in comments.

Comments

0

This happened to me after I added a schema location for the mysqldump like

<mysqldump xmlns="mysqldump"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="mysqldump mysqldump.xsd ">

After I removed the namespace, it worked:

<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.