I'm trying to implement functional tests with Liip's FunctionalTestBundle in a legacy Symfony 2.8 project.
This project uses hand-written postgresql queries in repositories and such, so I cannot force the usage of sqlite. Based on the bundle's documentation, I have to create the schema myself on test setup. I tried using the code snippet provided in the documentation.
public function setUp()
{
$em = $this->getContainer()->get('doctrine')->getManager();
if (!isset($metadatas)) {
$metadatas = $em->getMetadataFactory()->getAllMetadata();
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropDatabase();
if (!empty($metadatas)) {
$schemaTool->createSchema($metadatas);
}
$this->postFixtureSetup();
}
This fails on $schemaTool->createSchema($metadatas);
with the following error:
SQLSTATE[42P06]: Duplicate schema: 7 ERROR: schema "app" already exists' while executing DDL: CREATE SCHEMA app
/path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/ToolsException.php:39
/path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:96
My configuration is as follows:
# /path/to/project/app/config/config_test.yml
doctrine:
dbal:
default_connection: airlinesManager
connections:
airlinesManager:
driver: pdo_pgsql
memory: true
path: "%kernel.cache_dir%/test.db"
Dependencies:
# /path/to/project/composer.json
{
[...]
"require": {
"php": "^7.1",
"symfony/symfony": "2.8.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/common": "2.*",
"doctrine/dbal": "2.*",
"doctrine/doctrine-fixtures-bundle": "2.*",
[...]
},
"require-dev": {
[...],
"liip/functional-test-bundle": "^1.10"
},
[...]
}
Should I change my config to driver: pdo_sqlite
and remove the setUp snippet, everything works fine as long as fixtures are concerned. But I start getting errors when tests start using some hand-written postgresql queries.
Any ideas to make the schema thing work?
NB: For some reasons I cannot do any database operation from the symfony console. Here is an example when trying to drop the database.
php app/console doctrine:database:drop --force --env="test"
I always get the same error.
Could not drop database for connection named /path/to/project/app/cache/test/test.db
An exception occurred while executing 'DROP DATABASE /path/to/project/app/cache/test/test.db':
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "/"
LINE 1: DROP DATABASE /path/to/project/...
Then again, this works fine when using sqlite.
Aucun commentaire:
Enregistrer un commentaire