您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit平面数据格式flat的多表模式及多表状态断言
发布时间:2021-09-29 19:06:17编辑:雪饮阅读()
就前面的了解,flat平面数据格式像是上篇中用到的flat.xml就是放置的单表的数据结构,那么其实flat平面数据格式也是支持多表的,虽然之前我们用的多表模式是通过createMySQLXMLDataSet方法加载的mysqldump的输出文件。
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 01:15:23" />
<guestbook id="2" content="I like it!" user="nancy" created="2010-04-25 20:14:20" />
<guestbook_copy1 id="1" content="Hello buddy!" user="joe" created="2010-04-24 01:15:23" />
<guestbook_copy1 id="2" content="I like it!" user="nancy" created="2010-04-25 20:14:20" />
</dataset>
像是上篇中createDataSet中仅使用了'guestbook'单表,那么这里使用了'guestbook’和'guestbook_copy’多表进行表状态断言。 然后该多表状态断言就失败了:
use PHPUnit\DbUnit\DataSet\CsvDataSet;
use PHPUnit\Framework\TestCase;
use PHPUnit\DbUnit\TestCaseTrait;
class GuestbookTest extends TestCase
{
use TestCaseTrait;
static private $pdo = null;
private $conn = null;
final public function getConnection()
{
if ($this->conn === null) {
if (self::$pdo == null) {
self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
}
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
}
return $this->conn;
}
public function getDataSet()
{
$dataSet = new CsvDataSet();
$dataSet->addTable('guestbook', dirname(__FILE__)."/guestbook.csv");
return $dataSet;
}
public function testComplexQuery()
{
$dataSet = $this->getConnection()->createDataSet(['guestbook','guestbook_copy1']);
$expectedDataSet=$this->createFlatXmlDataSet(dirname(__FILE__).'/flat.xml');
$this->assertDataSetsEqual($expectedDataSet, $dataSet);
}
}
?>
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 01:15:23" />
<guestbook id="2" content="I like it!" user="nancy" created="2010-04-25 20:14:20" />
<guestbook_copy1 id="1" content="Hello buddy!" user="joe1" created="2010-04-24 01:15:23" />
<guestbook_copy1 id="2" content="I like it!" user="nancy" created="2010-04-25 20:14:20" />
</dataset>
关键字词:phpunit,flat,多表