jeudi 5 mai 2016

Unit tests pass when I change the order of tests

In my unit tests, I am using the following getDataSet method to set up DB. the test class extends from extends PHPUnit_Extensions_Database_TestCase

It looks like the framework is not deleting the and re inserting the rows before each test. The reason I feel that way is because my tests are passing when I change the order of some of the tests, which should never happen.

So Can anyone suggest what am I doing wrong .. or where should I look further to gain more insight ?

Also, I had to use composite Data Set as some of the older fixtures are in xml format, while new fixtures are in array format. Although no xml fixtures needs for this one.

public function getDataSet()
{

    $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
    /** @var  PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet $ds */
    $arrayDS = new ArrayDataSet([
        __DIR__ . '/seed-data/companies.php',
    ]);

    $compositeDs->addDataSet($arrayDS);

    return $compositeDs;
}

Could it be because I save pdo connection and reuse it ? as in follows

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;
}

Aucun commentaire:

Enregistrer un commentaire