PHPUnit数据库测试。夹具未设置?

时间:2011-07-13 06:58:25

标签: php mysql unit-testing phpunit database-testing

这篇文章于7月17日1:35 PM UTC + 8

更新

我有类似

的东西
require_once 'PHPUnit/Extensions/Database/TestCase.php';

class TestTest extends PHPUnit_Extensions_Database_TestCase {
    public function getConnection() {
        $pdo = new \PDO('mysql:host=localhost;dbname=jm_test', 'root', 'jm123');
        return $this->createDefaultDBConnection($pdo, 'jm_test');
    }   

    public function getDataSet() {
        return $this->createXMLDataSet(TEST_DIR . '/Fixtures/test.xml');
    }

    public function testRowCount() {
        $this->assertGreaterThan(0, $this->getConnection()->getRowCount('test'));
    }
}

Fixture(test.xml)

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <table name="test">
        <column>id</column>
        <column>key</column>
        <column>value</column>
    </table>
    <row>
        <value>1</value>
        <value>Key 1</value>
        <value>Value 1</value>
    </row>
    ...
</dataset>

我的行数总是为0,为什么会这样?

1 个答案:

答案 0 :(得分:2)

我发现了我的错误:我应该在<row>元素中移动<table>元素

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <table name="test">
        <column>id</column>
        <column>key</column>
        <column>value</column>
        <row>
            <value>1</value>
            <value>Key 1</value>
            <value>Value 1</value>
        </row>
        ...
    </table>
</dataset>