public function initializeDatabase()
{
// Get an instance of your entity manager
$entityManager = $this->app['orm.em'];
// Retrieve PDO instance
$pdo = $entityManager->getConnection()->getWrappedConnection();
// Clear Doctrine to be safe
$entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
$entityManager->clear();
gc_collect_cycles();
// Schema Tool to process our entities
$tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
$classes = $entityManager->getMetaDataFactory()->getAllMetaData();
// Drop all classes and re-build them for each test case
$tool->dropSchema($classes);
$tool->createSchema($classes);
$config = new Configuration($this->app['db']);
$config->setMigrationsNamespace('DoctrineMigrations');
$migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
$config->setMigrationsDirectory($migrationDir);
$config->registerMigrationsFromDirectory($migrationDir);
$migration = new Migration($config);
// initialize migrations.sql from bootstrap
if (!file_exists(sys_get_temp_dir() . '/migrations.sql')) {
$sql = $migration->migrate(null, false);
file_put_contents(sys_get_temp_dir() . '/migrations.sql', json_encode($sql));
} else {
$migrations = json_decode(file_get_contents(sys_get_temp_dir() . '/migrations.sql'), true);
foreach ($migrations as $migration_sql) {
foreach ($migration_sql as $sql) {
if ($this->isSqliteInMemory()) {
// XXX #1199 の問題を無理矢理回避...
$sql = preg_replace('/CURRENT_TIMESTAMP/i', "datetime('now','-9 hours')", $sql);
}
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
}
}
}
// 通常は eccube_install.sh で追加されるデータを追加する
$sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '[email protected]', '[email protected]', '[email protected]', '[email protected]', current_timestamp, 0)";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
}