2014-03-28 56 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; 
     } 
    } 
    ?>