/**
* Runs the drop and create commands on the fixtures if necessary.
*
* @param \Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
* @param Connection $db the datasource instance to use
* @param array $sources The existing tables in the datasource.
* @param bool $drop whether drop the fixture if it is already created or not
* @return void
*/
protected function _setupTable(TestFixture $fixture, Connection $db, array $sources, $drop = true)
{
if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
return;
}
$table = $fixture->table;
$exists = in_array($table, $sources);
if ($drop && $exists) {
$fixture->drop($db);
$fixture->create($db);
} elseif (!$exists) {
$fixture->create($db);
} else {
$fixture->created[] = $db->configName();
$fixture->truncate($db);
}
}