PHPUnit 数据库测试
我正在使用 PHPUnit 通过我的存储对象测试对象的插入。每个域对象都有一个添加的和最后修改的时间戳,由存储对象自动处理。我可以使用 PHPUnits DB 扩展方法assertDataSetsEqual 并作为 XML 数据集传递,如下所示。问题已添加,lastmodified 无法硬编码到 XML 数据集中,因为这会一直自动更改,我可以告诉 PHPUnit 忽略这些列吗?或者比较表输出的另一种方式(不是 XML),我可以忽略这些列?
测试
$user = new Social_User();
$user->setFk_mswuserId(10);
$user->setFirstName('Gavin');
$store = new Storage();
$store->save($user);
$xml_dataset = $this->createFlatXMLDataSet('after-new.xml');
$this->assertDataSetsEqual($xml_dataset, $this->getConnection()->createDataSet());
XML 数据集
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<user id="1" password="NULL" ip="0" added="0" authenticated="0" lat="0" lon="0" avatar="0" fk_mswuserId="1" timezoneoffset="0" firstName="Ben" lastName="Freeston" deleted="0" lastModified="0" />
<user id="2" password="NULL" ip="0" added="0" authenticated="0" lat="0" lon="0" avatar="0" fk_mswuserId="10" timezoneoffset="0" firstName="Gavin" lastName="Cooper" deleted="0" lastModified="0"/>
</dataset>
I am using PHPUnit to test insertion of objects via my storage object. Each domain object has a added and lastmodified timestamp, that is handled by the storage object automatically. I can using PHPUnits DB extensions method assertDataSetsEqual and passing as XML data set as below shows. The problem is added and lastmodified cannot be hardcoded into the XML dataset as this will change all the time automatically, can I tell PHPUnit to ignore these cols? or compare the tables output another way (not XML) where I can ignore these columns?
Test
$user = new Social_User();
$user->setFk_mswuserId(10);
$user->setFirstName('Gavin');
$store = new Storage();
$store->save($user);
$xml_dataset = $this->createFlatXMLDataSet('after-new.xml');
$this->assertDataSetsEqual($xml_dataset, $this->getConnection()->createDataSet());
XML Dataset
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<user id="1" password="NULL" ip="0" added="0" authenticated="0" lat="0" lon="0" avatar="0" fk_mswuserId="1" timezoneoffset="0" firstName="Ben" lastName="Freeston" deleted="0" lastModified="0" />
<user id="2" password="NULL" ip="0" added="0" authenticated="0" lat="0" lon="0" avatar="0" fk_mswuserId="10" timezoneoffset="0" firstName="Gavin" lastName="Cooper" deleted="0" lastModified="0"/>
</dataset>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据
这已经是内置的。
另请参阅 M.Lively(DBUnit 主要作者)的这些幻灯片
和 B. Eberlei 的 PHPUnit 数据库测试终极指南
http://www.phpunit.de/manual/dbunit.txt所以它应该按照以下方式工作
According to
this is already built-in.
Also see these slides by M.Lively (the main DBUnit author)
and B. Eberlei's Ultimate Guide to DB Testing with PHPUnit
http://www.phpunit.de/manual/dbunit.txtSo it should work along the lines of