diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da28f066..cf32b68b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,21 +21,24 @@ jobs: - php-version: 8.1 # add a specific job to test ^5.4 for all Symfony packages symfony-version: "^5.4" + # `theofidry/alice-data-fixtures:1.6.0` and `doctrine/dbal:^4.0` cause issues: + # Error: Call to undefined method Doctrine\DBAL\Connection::exec() + composer-flags: "require doctrine/dbal:^3.0" - php-version: 8.2 symfony-version: "^7.0" - php-version: 8.3 symfony-version: "^7.0" services: - mysql: - image: mysql:5.7 + mariadb: + image: mariadb:11.0 env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: acme + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: acme ports: - 3306:3306 postgresql: - image: postgres:9.6 + image: postgres:15-alpine env: POSTGRES_USER: 'postgres' POSTGRES_PASSWORD: 'postgres' diff --git a/composer.json b/composer.json index d47e5e9e..2b39a754 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "conflict": { "doctrine/annotations": "<1.13.1 || >=3.0", - "doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0", + "doctrine/dbal": "<2.13.1 || ~3.0.0 || >=5.0", "doctrine/mongodb-odm": "<2.2 || >=3.0", "doctrine/orm": "<2.14 || >=4.0" }, diff --git a/docker-compose.yml b/docker-compose.yml index a85cf579..322c2d88 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.1' services: mariadb: - image: 'mariadb:11.0' + image: 'mariadb:11' environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=acme diff --git a/src/Services/DatabaseToolCollection.php b/src/Services/DatabaseToolCollection.php index 31cfb64a..fea1d322 100644 --- a/src/Services/DatabaseToolCollection.php +++ b/src/Services/DatabaseToolCollection.php @@ -40,7 +40,9 @@ public function __construct(ContainerInterface $container, mixed $annotationRead public function add(AbstractDatabaseTool $databaseTool): void { - $this->items[$databaseTool->getType()][$databaseTool->getDriverName()] = $databaseTool; + $driverName = self::normalizeDriverName($databaseTool->getDriverName()); + + $this->items[$databaseTool->getType()][$driverName] = $databaseTool; } public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode = null): AbstractDatabaseTool @@ -49,6 +51,8 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode $registry = $this->container->get($registryName); $driverName = ('ORM' === $registry->getName()) ? \get_class($registry->getConnection()->getDatabasePlatform()) : 'default'; + $driverName = self::normalizeDriverName($driverName); + $databaseTool = $this->items[$registry->getName()][$driverName] ?? $this->items[$registry->getName()]['default']; $databaseTool->setRegistry($registry); @@ -57,4 +61,17 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode return $databaseTool; } + + /** + * On doctrine/dbal ^4.0, the class is named `SQLitePlatform`. + * On doctrine/dbal < 4.0, the class is named `SqlitePlatform`. + */ + private static function normalizeDriverName(string $driverName): string + { + if ('Doctrine\DBAL\Platforms\SqlitePlatform' === $driverName) { + return 'Doctrine\DBAL\Platforms\SQLitePlatform'; + } + + return $driverName; + } } diff --git a/tests/AppConfigMysql/config.yml b/tests/AppConfigMysql/config.yml index 21b15610..86952cee 100644 --- a/tests/AppConfigMysql/config.yml +++ b/tests/AppConfigMysql/config.yml @@ -8,3 +8,4 @@ doctrine: dbname: acme user: root password: root + server_version: '11' diff --git a/tests/AppConfigMysqlUrl/config.yml b/tests/AppConfigMysqlUrl/config.yml index 2cbdd85f..2ec48e8e 100644 --- a/tests/AppConfigMysqlUrl/config.yml +++ b/tests/AppConfigMysqlUrl/config.yml @@ -2,5 +2,5 @@ doctrine: dbal: - url: 'mysql://root:root@mariadb:3306/foobar' + url: 'mysql://root:root@mariadb:3306/foobar?serverVersion=11' driver: pdo_mysql diff --git a/tests/AppConfigPgsql/config.yml b/tests/AppConfigPgsql/config.yml index 21e362dc..1b6e052f 100644 --- a/tests/AppConfigPgsql/config.yml +++ b/tests/AppConfigPgsql/config.yml @@ -8,3 +8,4 @@ doctrine: dbname: postgres user: postgres password: postgres + server_version: '15'