diff --git a/src/Console/DoctrineHelper.php b/src/Console/DoctrineHelper.php index 7774966a..8050af4f 100644 --- a/src/Console/DoctrineHelper.php +++ b/src/Console/DoctrineHelper.php @@ -60,11 +60,15 @@ public function hasDatabase(Connection $connection, string $databaseName): bool public function createDatabase(Connection $connection, string $databaseName): void { - $connection->createSchemaManager()->createDatabase($databaseName); + $connection->createSchemaManager()->createDatabase( + $connection->getDatabasePlatform()->quoteSingleIdentifier($databaseName) + ); } public function dropDatabase(Connection $connection, string $databaseName): void { - $connection->createSchemaManager()->dropDatabase($databaseName); + $connection->createSchemaManager()->dropDatabase( + $connection->getDatabasePlatform()->quoteSingleIdentifier($databaseName) + ); } } diff --git a/tests/Unit/Console/DoctrineHelperTest.php b/tests/Unit/Console/DoctrineHelperTest.php index 71379aae..f4faaf0d 100644 --- a/tests/Unit/Console/DoctrineHelperTest.php +++ b/tests/Unit/Console/DoctrineHelperTest.php @@ -5,6 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Unit\Console; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use InvalidArgumentException; use Patchlevel\EventSourcing\Console\DoctrineHelper; @@ -66,9 +67,10 @@ public function testCreateDatabase(): void $helper = new DoctrineHelper(); $schemaManager = $this->prophesize(AbstractSchemaManager::class); - $schemaManager->createDatabase('test')->shouldBeCalled(); + $schemaManager->createDatabase('`test`')->shouldBeCalled(); $connection = $this->prophesize(Connection::class); + $connection->getDatabasePlatform()->willReturn(new MySQLPlatform()); $connection->createSchemaManager()->willReturn($schemaManager); $helper->createDatabase($connection->reveal(), 'test'); @@ -79,9 +81,10 @@ public function testDropDatabase(): void $helper = new DoctrineHelper(); $schemaManager = $this->prophesize(AbstractSchemaManager::class); - $schemaManager->dropDatabase('test')->shouldBeCalled(); + $schemaManager->dropDatabase('`test`')->shouldBeCalled(); $connection = $this->prophesize(Connection::class); + $connection->getDatabasePlatform()->willReturn(new MySQLPlatform()); $connection->createSchemaManager()->willReturn($schemaManager); $helper->dropDatabase($connection->reveal(), 'test');