[2.0] ResetDatabase with DamaDoctrineTestBundle and symfony/doctrine-messenger library
After migrate to version 2.0. My test was broken, because database not refresh before each test. I have warning
Exception in third-party event subscriber: There is already an active transaction
#0 /var/www/vendor/doctrine/dbal/src/Driver/PDO/Connection.php(119): Doctrine\DBAL\Driver\PDO\PDOException::new(Object(PDOException))
#1 /var/www/vendor/dama/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php(60): Doctrine\DBAL\Driver\PDO\Connection->beginTransaction()
#2 /var/www/vendor/dama/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/PHPUnit/PHPUnitExtension.php(57): DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::beginTransaction()
My stack
- Symfony 6.4
- Php 8.3
- PhpUnit 11
After debug, I found problem (I think so)
In function
PersistenceManager::resetDatabase
line 97 - 102
if ($isDAMADoctrineTestBundleEnabled) {
// re-enable static connections
StaticDriver::setKeepStaticConnections(true);
}
$shutdownKernel();
In function $shutdownKernel call KernelTestCase::ensureKernelShutdown
And in KernelTestCase::ensureKernelShutdown exist code
if ($container instanceof ResetInterface) {
$container->reset();
}
And if install library symfony/doctrine-messenger for doctrine transport
In this reset execute query
$this->executeStatement(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
But static connection in DAMADoctrineTestBundle already is true.
If in PersistenceManager::resetDatabase first call $shutdownKernel(); and then set static connection, all works fine.
I have same problem.
I remove symfony/doctrine-messenger and go use RabbitMq ;)
hey, this has been fixed by https://github.com/zenstruck/foundry/pull/690 which will be released soon!