diff --git a/Storage/DoctrineStorage.php b/Storage/DoctrineStorage.php index f134341a..b2c5334c 100644 --- a/Storage/DoctrineStorage.php +++ b/Storage/DoctrineStorage.php @@ -150,13 +150,9 @@ private function tableExists() { } private function createTable() { - // TODO remove as soon as Doctrine DBAL >= 3.0 is required - $stringType = defined('Doctrine\DBAL\Types\Types::STRING') ? Types::STRING : Type::STRING; - $arrayType = defined('Doctrine\DBAL\Types\Types::ARRAY') ? Types::ARRAY : Type::TARRAY; - $table = new Table(self::TABLE, [ - new Column($this->keyColumn, Type::getType($stringType)), - new Column($this->valueColumn, Type::getType($arrayType)), + new Column($this->keyColumn, Type::getType(Types::STRING), ['length' => 255]), + new Column($this->valueColumn, Type::getType(Types::ARRAY), ['length' => 255]), ]); $table->setPrimaryKey([$this->keyColumn]); diff --git a/Tests/Storage/DoctrineStorageTest.php b/Tests/Storage/DoctrineStorageTest.php index 4fd71f4e..d8361107 100644 --- a/Tests/Storage/DoctrineStorageTest.php +++ b/Tests/Storage/DoctrineStorageTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; +use Doctrine\DBAL\Tools\DsnParser; /** * @group unit @@ -40,9 +41,17 @@ protected function getStorageImplementation() { $this->markTestSkipped('Environment variable DB_DSN is not set.'); } - $this->conn = DriverManager::getConnection([ - 'url' => $_ENV['DB_DSN'], - ], $configuration); + $dsn = $_ENV['DB_DSN']; + // TODO use DsnParser as soon as DBAL >= 3.6 is required + $params = class_exists(DsnParser::class) + ? (new DsnParser([ + 'mysql' => 'pdo_mysql', + 'pgsql' => 'pdo_pgsql', + 'sqlite' => 'pdo_sqlite', + ]))->parse($dsn) + : ['url' => $dsn]; + + $this->conn = DriverManager::getConnection($params, $configuration); $generator = $this->createMock(StorageKeyGeneratorInterface::class); diff --git a/composer.json b/composer.json index 3e6b0173..8610e62b 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "craue/translations-tests": "^1.1", "doctrine/collections": "^1.8 || ^2.1", "doctrine/common": "^2.9 || ^3.0", + "doctrine/dbal": "^2.10 || ^3.0", "doctrine/doctrine-bundle": "^1.10 || ^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.10", @@ -52,6 +53,9 @@ "symfony/security-bundle": "^4.4 || ^5.4 || ^6.3", "symfony/twig-bundle": "^4.4 || ^5.4 || ^6.3" }, + "conflict": { + "doctrine/dbal": "<2.10" + }, "minimum-stability": "stable", "autoload": { "psr-4": {