Skip to content

Commit 52e0d4f

Browse files
committed
change test db
1 parent 7d26acc commit 52e0d4f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

config/config_test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ framework:
1111

1212
doctrine:
1313
dbal:
14-
driver: 'pdo_sqlite'
15-
memory: true
14+
driver: 'pdo_mysql'
15+
host: '%database_host%'
16+
path: '%database_path%'
17+
port: '%database_port%'
18+
dbname: 'phplist'
19+
user: '%database_user%'
20+
password: '%database_password%'
1621
charset: UTF8
1722
# orm:
1823
# entity_managers:

src/TestingSupport/Traits/DatabaseTestTrait.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,25 @@ protected function loadSchema(): void
8383
$schemaTool = new SchemaTool($this->entityManager);
8484
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
8585

86-
$connection = $this->entityManager->getConnection();
87-
$schemaManager = $connection->createSchemaManager();
86+
// Create all tables at once to handle dependencies properly
87+
try {
88+
$schemaTool->createSchema($metadata);
89+
} catch (ToolsException $e) {
90+
// If creating all tables at once fails, try to create them one by one
91+
// This is a fallback mechanism
92+
$connection = $this->entityManager->getConnection();
93+
$schemaManager = $connection->createSchemaManager();
8894

89-
foreach ($metadata as $classMetadata) {
90-
$tableName = $classMetadata->getTableName();
95+
foreach ($metadata as $classMetadata) {
96+
$tableName = $classMetadata->getTableName();
9197

92-
if (!$schemaManager->tablesExist([$tableName])) {
93-
try {
94-
$schemaTool->createSchema([$classMetadata]);
95-
} catch (ToolsException $e) {
96-
// nothing to do
97-
echo $e->getMessage();
98+
if (!$schemaManager->tablesExist([$tableName])) {
99+
try {
100+
$schemaTool->createSchema([$classMetadata]);
101+
} catch (ToolsException $e) {
102+
// Log the error but continue with other tables
103+
echo $e->getMessage() . PHP_EOL;
104+
}
98105
}
99106
}
100107
}

0 commit comments

Comments
 (0)