2014-03-28 14 views
0

php/dbunit错误,当在表中为空 我得到和错误测试存储过程或查询包含或返回一个NULL值时,我已经尝试了同样的例子doest返回任何NULL值和它的作品完美,我怎么能代表NULL在XML文件来测试它php/dbunit错误,当在表中为空

试验规程

 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)中,它给了我同样的错误。为什么是这样?

+0

只是胡乱猜测,如果从XML文件中删除了“”行会发生什么?毕竟,“”与NULL完全不同。 – Jasper

+0

得到一个错误 的RuntimeException:AttValue:“或”预期 属性构建错误 找不到开始标记结束 – Terence

+0

感谢您的答复真的意味着很多对我的感谢 – Terence

回答

0

根据该文件,

http://dbunit.sourceforge.net/faq.html#flatxmlnull

留出整个属性应该这样做,就像这样:

<?xml version="1.0" encoding="UTF-8"?> 
    <dataset> 
    <Star 
     productId ="4" 
     createdOn ="2012-12-12 12:12:12" 
     originalImage ="link" 
     title ="Christopher Knight H" 
     url ="link" 
    /> 
    </dataset> 
+0

感谢重播 – Terence

+0

,但是, 我在Ubuntu 12.04 LTS(phpunit 3.7.28)尝试相同的代码,它工作正常包括“”in xml) 而在Debian 6.0.8(phpunit 4.0.12)中,它给了我同样的错误 我想这是因为phphunit版本..我只是试图降级phpunit的版本和拿回 – Terence

+0

降级仍然是错误依然 – Terence

0

PHPUnit的提供替换的数据集,是对现有的一个装饰数据集并允许您用另一个替换值替换数据集的任何列中的值。例如,如果XML类似于

<?xml version="1.0" encoding="UTF-8"?> 
    <dataset> 
    <guestbook id="1" user="joe" created="2014-04-13 17:15:23" /> 
    <guestbook id="2" user="##NULL##" created="2014-04-20 12:14:20" /> 
    </dataset> 

包裹平整的XML数据集为数据集替换如下

<?php 
    class ReplacementTest extends PHPUnit_Extensions_Database_TestCase 
    { 
     public function getDataSet() 
     { 
      $ds = $this->createFlatXmlDataSet('myFlatXmlFixture.xml'); 
      $rds = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($ds); 
      $rds->addFullReplacement('##NULL##', null); 
      return $rds; 
     } 
    } 
    ?> 
相关问题