[英]mysqldump xml format and dbunit expected xml format in phpunit test in php
I am working in phpunit testing with dbunit. 我正在使用dbunit进行phpunit测试。 This is my first time testing in php. 这是我第一次在php上测试。
I am creating xml by this command: 我通过这个命令创建xml:
mysqldump --xml -t -u username -p database > seed.xml
After that as per doc xml should be in below format: 之后根据doc xml应该采用以下格式:
<?xml version="1.0" ?>
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 17:15:23" />
<guestbook id="2" content="I like it!" created="2010-04-26 12:14:20" />
</dataset>
But in my generated xml it looks like: 但在我生成的xml中,它看起来像:
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="demo_app">
<table_data name="test">
<row>
<field name="id">1</field>
</row>
</table_data>
<table_data name="test2">
<row>
<field name="id">1</field>
<field name="name">asdas</field>
</row>
<row>
<field name="id">2</field>
<field name="name">asDASD</field>
</row>
</table_data>
</database>
</mysqldump>
When I am trying to run this in my test class: 当我试图在我的测试类中运行它时:
$this->createMySQLXMLDataSet('seed.xml');
I get this error: 我收到此错误:
PHPUnit_Extensions_Database_Exception: The root element of a flat xml data set file must be called PHPUnit_Extensions_Database_Exception:必须调用平面xml数据集文件的根元素
I am using phpunit 4.1.0 and dbunit 1.3 我使用的是phpunit 4.1.0和dbunit 1.3
How can I generate xml in the expected format or how can I get rid of this issue? 如何以预期的格式生成xml或如何摆脱此问题?
The format from the documentation that you reference is for a Flat XML Dataset, which is not what is expected when using createMySQLXMLDataSet()
. 您引用的文档中的格式是针对Flat XML Dataset的,这与使用createMySQLXMLDataSet()
时的预期不同。
From your error, though, it seems as if you were actually calling createFlatXmlDataSet()
by mistake. 但是,从您的错误来看,似乎您实际上错误地调用了createFlatXmlDataSet()
。
You should reference the file you generated with mysqldump
in a createMySQLXMLDataSet()
call. 您应该在createMySQLXMLDataSet()
调用中引用您使用mysqldump
生成的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.