1

I'm trying to create an initial DB state in DB Unit like this...

public function getDataSet() {
        $primary = new \PHPUnit\DbUnit\DataSet\CompositeDataSet();
        $fixturePaths = [
            "test/Seeds/Upc/DB/UpcSelect.xml",
            "test/Seeds/Generic/DB/ProductUpcSelect.xml"
        ];
        foreach($fixturePaths as $fixturePath) {
            $dataSet = $this->createXmlDataSet($fixturePath);
            $primary->addDataSet($dataSet);
        }
        return $primary;
    }

Then after my query I'm attempting to call this user-defined function...

protected function compareDatabase(String $seedPath, String $table) {
    $expected = $this->createFlatXmlDataSet($seedPath)->getTable($table);
    $result = $this->getConnection()->createQueryTable($table, "SELECT * FROM $table");
    $this->assertTablesEqual($expected, $result);
  }

The idea here is that I have an initial DB state, run my query, then compare the actual table state with the XML data set representing what I expect the table to look like. This process is described in PHPUnit's documentation for DBUnit but I keep having an exception thrown...

PHPUnit\DbUnit\InvalidArgumentException: There is already a table named upc with different table definition

Test example...

public function testDeleteByUpc() {
    $mapper = new UpcMapper($this->getPdo());
    $mapper->deleteByUpc("someUpcCode1");
    $this->compareDatabase("test/Seeds/Upc/DB/UpcAfterDelete.xml", 'upc');
  }

I seem to be following the docs...how is this supposed to be done?

1 Answer 1

1

This was actually unrelated to creating a second XML Dataset. This exception was thrown because the two fixtures I loaded in my getDataSet() method both had table definitions for upc.

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

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.