这篇文章于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,为什么会这样?
答案 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>