【发布时间】:2014-05-07 18:09:12
【问题描述】:
表中为空时的php/dbunit错误 我在测试包含或返回 NULL 值的存储过程或查询时出错,我尝试了相同的示例,它不返回任何 NULL 值并且它工作完美,我如何在 XML 文件中表示 NULL 来测试它
测试代码
public function StarRead()
{
fwrite(STDOUT, __METHOD__ . " Check with valid data \n");
$resultTable = $this->getConnection()->createQueryTable(
'Star', 'CALL get_star(1,NULL,0,2)'
);
$expected = $this->createFlatXMLDataSet(dirname(__FILE__).'/_files/new.xml');
$expectedTable = $expected->getTable('Star');
//Here we check that the table in the database matches the data in the XML file
$this->assertTablesEqual($expectedTable, $resultTable);
}
XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<Star
productId ="4"
currentPrice =""
listPrice =""
createdOn ="2012-12-12 12:12:12"
originalImage ="link"
merchantName =""
title ="Christopher Knight H"
url ="link"
/>
</dataset>
输出:
PHPUnit 4.0.12 by Sebastian Bergmann.
DBTest::StarRead Check with valid data F
Time: 1.4 seconds, Memory: 8.50Mb
There was 1 failure:
1) DBTest::StarRead Failed asserting that +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | AutoStar | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | productId | currentPrice | listPrice | createdOn | originalImage | merchantName | title | url | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | 4 | NULL | NULL | 2012-12-12 12:12:12 | link | NULL | Christopher Knight H | link | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
is equal to expected (table diff enabled) +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | AutoStar | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | productId | currentPrice | listPrice | createdOn | originalImage | merchantName | title | url | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ | 4 | | | 2012-12-12 12:12:12 | link | | Christopher Knight H | link | +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+
.
FAILURES! Tests: 1, Assertions: 1, Failures: 1.
我在 Ubuntu 12.04 LTS (phpunit 3.7.28) 中尝试了相同的代码,它运行良好。
在 Debian 6.0.8 (phpunit 4.0.12) 中,它给了我同样的错误。这是为什么呢?
【问题讨论】:
-
只是一个疯狂的猜测,如果你从 XML 文件中删除带有 "" 的行会发生什么?毕竟,"" 和 NULL 是完全不同的东西。
-
得到一个错误 RuntimeException: AttValue: " or ' 预期属性构造错误 找不到开始标记的结尾
-
感谢您的回复,这对我来说真的很重要,谢谢
-
是的,请尝试以这种方式保持非空条目或“”,然后它会成功运行。但是那么 null 或 "" 实体呢
标签: xml unit-testing phpunit dbunit database-testing