after reading the document of PHPUnit to write the database test, we should first establish the base, mainly to write a setup function, which is my
.protected function setUp() : void
{
// mysql
$conn = $this->getConnection();
// PDO
$pdo = $conn->getConnection();
// set up tables
$fixtureDataSet = $this->getDataSet();
foreach ($fixtureDataSet->getTableNames() as $table) {
// drop table
$pdo->exec("DROP TABLE IF EXISTS `$table`;");
// recreate table
//Returns a table meta data object for the given table
$meta = $fixtureDataSet->getTableMetaData($table);
$create = "CREATE TABLE IF NOT EXISTS `$table` ";
$cols = array();
foreach ($meta->getColumns() as $col) {
$cols[] = "`$col` VARCHAR(200)";
}
$create .= "(".implode(",", $cols).");";
$pdo->exec($create);
}
parent::setUp();
}
but in this case, the fields that create the table are all varchar, and I think the class getColumns
of $meta returns an array of strings, and I don"t know where to get the field definition information?
this is the xml file from MySQLdump
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="ucenter">
<table_structure name="uc_assets_log">
<field Field="id" Type="int(10) unsigned" Null="NO" Key="PRI" Extra="auto_increment" Comment="" />
<field Field="uid" Type="int(10)" Null="NO" Key="MUL" Extra="" Comment="" />
<field Field="type" Type="tinyint(1) unsigned" Null="NO" Key="" Default="1" Extra="" Comment="1:U 2:" />
<field Field="number" Type="decimal(10,2)" Null="NO" Key="" Extra="" Comment="" />
<field Field="charm" Type="float(10,2)" Null="NO" Key="" Default="0.00" Extra="" Comment="" />
<field Field="dateline" Type="int(10)" Null="NO" Key="MUL" Extra="" Comment="" />
<field Field="buid" Type="int(10)" Null="NO" Key="MUL" Default="0" Extra="" Comment="" />
<field Field="pay" Type="decimal(10,2)" Null="NO" Key="" Default="0.00" Extra="" Comment="" />
</table_structure>
<table_data name="uc_assets_log">
</table_data>
</database>
</mysqldump>