开发者

PHPUnit Database Testing. Fixtures not set?

开发者 https://www.devze.com 2023-03-20 02:56 出处:网络
this post was updated on 17 July 1:35PM UTC+8 I have something like require_once \'PHPUnit/Extensions/Database/TestCase.php\';

this post was updated on 17 July 1:35PM UTC+8

I have something like

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>

I always get a row count of 0 why is that?


I found my mistake: I should move the <row> element inside the <table> element

<?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>
0

精彩评论

暂无评论...
验证码 换一张
取 消