I am working in phpunit testing with dbunit. This is my first time testing in php.
I am creating xml by this command:
mysqldump --xml -t -u username -p database > seed.xml
After that as per doc xml should be in below format:
<?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 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
I am using phpunit 4.1.0 and dbunit 1.3
How can I generate xml in the expected format or how can I get rid of this issue?
The format from the documentation that you reference is for a Flat XML Dataset, which is not what is expected when using createMySQLXMLDataSet()
.
From your error, though, it seems as if you were actually calling createFlatXmlDataSet()
by mistake.
You should reference the file you generated with mysqldump
in a createMySQLXMLDataSet()
call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.