我正在尝试在DB Unit中创建一个初始DB状态,就像这样......
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;
}
然后我的查询后我试图调用这个用户定义的函数......
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);
}
这里的想法是我有一个初始的DB状态,运行我的查询,然后将实际的表状态与表示我期望表格的XML数据集进行比较。这个过程在PHPUnit's documentation for DBUnit中描述,但我一直抛出异常...
PHPUnit\DbUnit\InvalidArgumentException: There is already a table named upc with different table definition
测试示例......
public function testDeleteByUpc() {
$mapper = new UpcMapper($this->getPdo());
$mapper->deleteByUpc("someUpcCode1");
$this->compareDatabase("test/Seeds/Upc/DB/UpcAfterDelete.xml", 'upc');
}
我似乎在关注文档......这应该怎么做?
答案 0 :(得分:1)
这实际上与创建第二个XML数据集无关。抛出此异常是因为我在getDataSet()
方法中加载的两个灯具都具有upc
的表定义。