/**
* Sets database into a specific test.
*/
public function setDB($db_data)
{
$this->tables = array_keys($db_data);
// create databases
foreach ($db_data as $table => $data) {
$s = new Structure(['connection' => $this->db->connection]);
$s->table($table)->drop();
$first_row = current($data);
foreach ($first_row as $field => $row) {
if ($field === 'id') {
$s->id('id');
continue;
}
if (is_int($row)) {
$s->field($field, ['type' => 'integer']);
continue;
}
$s->field($field);
}
if (!isset($first_row['id'])) {
$s->id();
}
$s->create();
$has_id = (bool) key($data);
foreach ($data as $id => $row) {
$s = new Query(['connection' => $this->db->connection]);
if ($id === '_') {
continue;
}
$s->table($table);
$s->set($row);
if (!isset($row['id']) && $has_id) {
$s->set('id', $id);
}
$s->insert();
}
}
}