このようなDBユニットで初期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 の 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');
}
私はドキュメントに従っているようです...これはどのように行われるべきですか?