Skip to content

Commit

Permalink
Merge pull request #299 from icanhazstring/patch-1
Browse files Browse the repository at this point in the history
Fix problem with database names using hyphens
  • Loading branch information
DavidBadura authored Jul 29, 2022
2 parents c9f84a9 + f256b2c commit 26f77f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Console/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
7 changes: 5 additions & 2 deletions tests/Unit/Console/DoctrineHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 26f77f3

Please sign in to comment.