Skip to content

Commit

Permalink
Merge pull request #15 from liip/fix-conflict-with-dama-doctrine-test…
Browse files Browse the repository at this point in the history
…-bundle

Fix conflict with dama/doctrine-test-bundle
  • Loading branch information
alexislefebvre committed Jul 15, 2019
2 parents 16000bb + 836599c commit 3fd247f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,3 +1,9 @@
# Changelog

## 1.0 [TBA]
## 1.1.0 (TBA)

- Added parameter `liip_test_fixtures.keep_database_and_schema` to avoid issue with [DAMADoctrineTestBundle](https://github.com/dmaicher/doctrine-test-bundle)

## 1.0.0 (2019-06-11)

Initial release, code extracted from [LiipFunctionalTestBundle](https://github.com/liip/LiipFunctionalTestBundle)
12 changes: 4 additions & 8 deletions doc/caveats.md
Expand Up @@ -4,19 +4,15 @@

### DAMADoctrineTestBundle

Due to conflicting operations with databases, this bundle has compatibility issues with [DAMADoctrineTestBundle](https://github.com/dmaicher/doctrine-test-bundle).

This triggers the following error:
Due to conflicting operations with databases, this bundle can trigger the following error with [DAMADoctrineTestBundle](https://github.com/dmaicher/doctrine-test-bundle):

```
Doctrine\DBAL\Driver\PDOException: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT DOCTRINE2_SAVEPOINT_2 does not exist
```

Use the following configuration to avoid this issue:
To avoid this, disable automatic changes to database and schema:

```
dama_doctrine_test:
enable_static_connection: false
liip_test_fixtures:
keep_database_and_schema: true
```

See https://github.com/liip/LiipFunctionalTestBundle/issues/423 and https://github.com/dmaicher/doctrine-test-bundle/issues/58 for reference
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Expand Up @@ -46,7 +46,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->end()
->end()
->booleanNode('keep_database_and_schema')->defaultFalse()->end()
;

return $treeBuilder;
Expand Down
8 changes: 8 additions & 0 deletions src/Services/DatabaseTools/AbstractDatabaseTool.php
Expand Up @@ -25,6 +25,8 @@
*/
abstract class AbstractDatabaseTool
{
const KEEP_DATABASE_AND_SCHEMA_PARAMETER_NAME = 'liip_test_fixtures.keep_database_and_schema';

protected $container;

protected $fixturesLoaderFactory;
Expand Down Expand Up @@ -200,4 +202,10 @@ public function setExcludedDoctrineTables(array $excludedDoctrineTables): void
{
$this->excludedDoctrineTables = $excludedDoctrineTables;
}

protected function getKeepDatabaseAndSchemaParameter()
{
return $this->container->hasParameter(self::KEEP_DATABASE_AND_SCHEMA_PARAMETER_NAME)
&& true === $this->container->getParameter(self::KEEP_DATABASE_AND_SCHEMA_PARAMETER_NAME);
}
}
22 changes: 13 additions & 9 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Expand Up @@ -125,17 +125,21 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst
}

// TODO: handle case when using persistent connections. Fail loudly?
$schemaTool = new SchemaTool($this->om);
if (count($this->excludedDoctrineTables) > 0 || true === $append) {
if (!empty($this->getMetadatas())) {
$schemaTool->updateSchema($this->getMetadatas());
}
} else {
$schemaTool->dropDatabase();
if (!empty($this->getMetadatas())) {
$schemaTool->createSchema($this->getMetadatas());
if (false === $this->getKeepDatabaseAndSchemaParameter()) {

$schemaTool = new SchemaTool($this->om);
if (count($this->excludedDoctrineTables) > 0 || true === $append) {
if (!empty($this->getMetadatas())) {
$schemaTool->updateSchema($this->getMetadatas());
}
} else {
$schemaTool->dropDatabase();
if (!empty($this->getMetadatas())) {
$schemaTool->createSchema($this->getMetadatas());
}
}
}

$this->webTestCase->postFixtureSetup();

$executor = $this->getExecutor($this->getPurger());
Expand Down

0 comments on commit 3fd247f

Please sign in to comment.