0

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

4

2 回答 2

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>
于 2014-03-28T12:36:59.317 回答
0

PHPUnit 提供 Replacement DataSet,它是现有数据集的装饰器,允许您将数据集的任何列中的值替换为另一个替换值。例如,如果 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>

将 Flat XML DataSet 包装成 Replacement DataSet,如下所示

    <?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;
        }
    }
    ?>
于 2014-10-07T09:16:57.763 回答