liip / LiipTestFixturesBundle

This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications
https://liip.ch
MIT License
165 stars 45 forks source link

[Bug]: Creating database if not exists fails #315

Closed philipsorst closed 2 months ago

philipsorst commented 2 months ago

Preconditions

liip/test-fixtures-bundle: 3.0.1
doctrine/orm: 3.2.0
doctrine/dbal: 4.0.4
doctrine/doctrine-bundle: 2.12.0
symfony/*: 6.4.*

Steps to reproduce

Connection string:

DATABASE_URL="postgresql://user:password@postgres:5432/database?serverVersion=14.5&charset=utf8"

Doctrine test config:

when@test:
    doctrine:
        dbal:
            # "TEST_TOKEN" is typically set by ParaTest
            dbname_suffix: '_test%env(default::TEST_TOKEN)%'

Expected result

The tests run.

Actual result

Doctrine\DBAL\Exception\ConnectionException : An exception occurred in the driver: SQLSTATE[08006] [7] connection to server at "postgres", port 5432 failed: FATAL: database "user" does not exist is shown in all tests.

Investigation

https://github.com/liip/LiipTestFixturesBundle/blob/203df6491eb0d2981317030cca06ecd598b48eda/src/Services/DatabaseTools/ORMDatabaseTool.php#L131-L134

In ORMDatabaseTool::createDatabaseIfNotExists() the dbname and url parameters are unset. When I comment the line, the tests run again. As there is a comment below the code, it seems that there is a reason for unsetting those that point to SQLite. However it does not work with the dependency set as given above and a PostgreSQL Database.

philipsorst commented 2 months ago

Ok, this seems to be a doctrine/dbal bug as the PDO driver does not use the postgres default value for dbname if non is set.