阻止 PHPUnit 的 DBUnit 在数据库中插入 XML 数据集
Stop PHPUnit's DBUnit from inserting XML dataset in database
有没有办法阻止 DBUnit 基于 XML 数据集创建记录?
我正在尝试测试查询是否会插入一条记录,然后将其与 XML 数据集进行比较。
public function testInsert()
{
$statement = $this->getConnection()
->getConnection()
->query(
'insert into Grades (Vendor) values (\'test\')'
);
$actual = $this->getConnection()->createQueryTable(
'Grades',
'select Vendor from Grades'
);
$this->assertTablesEqual(
$this->getDataSet()->getTable('Grades'),
$actual
);
}
public function getDataset()
{
//returns dataset below
}
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
uid="345"
/>
</dataset>
结果是:
PHPUnit: Failed asserting that
+----------------------+
| Grades |
+----------------------+
| Vendor |
+----------------------+
| test |
+----------------------+
| test |
+----------------------+
is equal to expected
+----------------------+
| Grades |
+----------------------+
| Vendor |
+----------------------+
| test |
+----------------------+
有人可以解释为什么要插入 XML 数据集吗?我如何才能阻止它自动插入?
发现我应该在比较结果之前使用空 "base" table XML。
public function getDataSet()
{
return $this->createFlatXMLDataSet("seed.xml");
}
public function testUpdate()
{
$statement = $this->getConnection()
->getConnection()
->query(
'insert into Grades (Vendor) values (\'test\')'
);
$actual = new \PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection());
$actual->addTable(
'Grades',
'select Vendor from Grades'
);
$expected = $this->createFlatXMLDataSet("expected.xml");
$this->assertDataSetsEqual(
$expected,
$actual
);
}
seed.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
/>
</dataset>
expected.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
Vendor="test"
/>
</dataset>
有没有办法阻止 DBUnit 基于 XML 数据集创建记录?
我正在尝试测试查询是否会插入一条记录,然后将其与 XML 数据集进行比较。
public function testInsert()
{
$statement = $this->getConnection()
->getConnection()
->query(
'insert into Grades (Vendor) values (\'test\')'
);
$actual = $this->getConnection()->createQueryTable(
'Grades',
'select Vendor from Grades'
);
$this->assertTablesEqual(
$this->getDataSet()->getTable('Grades'),
$actual
);
}
public function getDataset()
{
//returns dataset below
}
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
uid="345"
/>
</dataset>
结果是:
PHPUnit: Failed asserting that
+----------------------+
| Grades |
+----------------------+
| Vendor |
+----------------------+
| test |
+----------------------+
| test |
+----------------------+
is equal to expected
+----------------------+
| Grades |
+----------------------+
| Vendor |
+----------------------+
| test |
+----------------------+
有人可以解释为什么要插入 XML 数据集吗?我如何才能阻止它自动插入?
发现我应该在比较结果之前使用空 "base" table XML。
public function getDataSet()
{
return $this->createFlatXMLDataSet("seed.xml");
}
public function testUpdate()
{
$statement = $this->getConnection()
->getConnection()
->query(
'insert into Grades (Vendor) values (\'test\')'
);
$actual = new \PHPUnit_Extensions_Database_DataSet_QueryDataSet($this->getConnection());
$actual->addTable(
'Grades',
'select Vendor from Grades'
);
$expected = $this->createFlatXMLDataSet("expected.xml");
$this->assertDataSetsEqual(
$expected,
$actual
);
}
seed.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
/>
</dataset>
expected.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<Grades
Vendor="test"
/>
</dataset>