PHPUnit Database Extension - How to have an empty dataset?
Asked Answered
P

1

10

I want to create a test table that is empty. Using the Example from digitalsandwich, I want something like:

require_once 'PHPUnit/Extensions/Database/TestCase.php';
class BankAccountDBTest extends PHPUnit_Extensions_Database_TestCase
{
    protected $pdo;

    public function __construct()
    {
        $this->pdo = new PDO('sqlite::memory:');
        BankAccount::createTable($this->pdo);
    }

    protected function getConnection()
    {
        return $this->createDefaultDBConnection($this->pdo, 'sqlite');
    }

    protected function getDataSet()
    {
        return $this->createFlatXMLDataSet(dirname(__FILE__).'/_files/empty-seed.xml');
    }

    public function testEmptyTableBehavior() 
    {
        // test stuff
    }
}

Should I be using a different method than createFlatXMLDataSet()? Or???

Panlogism answered 1/10, 2009 at 16:29 Comment(0)
P
22

Ok, I figured it out:

...
require_once 'PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php';
class BankAccountDBTest extends PHPUnit_Extensions_Database_TestCase
{
...
    protected function getDataSet()
    {
        return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet();
    }
Panlogism answered 1/10, 2009 at 18:49 Comment(1)
I just wanted to add that this is not true anymore for newer versions. I think since PHPUnit 6.0 they are using namespaces here: return new PHPUnit\DbUnit\DataSet\DefaultDataSet();Amused

© 2022 - 2024 — McMap. All rights reserved.