Closed B-Galati closed 2 years ago
My current workaround is to call this kind of code in a PHPUnit hook:
class PHPUnitExtension implements BeforeTestHook
{
public function executeBeforeTest(string $test): void
{
$this->resetDatabaseConnectionOfDamaTestBundle();
}
private function resetDatabaseConnectionOfDamaTestBundle(): void
{
static $reflectionProperty = null;
if ($reflectionProperty === null) {
$reflectionClass = new \ReflectionClass(\DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::class);
$reflectionProperty = $reflectionClass->getProperty('connections');
$reflectionProperty->setAccessible(true);
}
$reflectionProperty->setValue(StaticDriver::class, []);
}
}
Hm that is quite a special case I guess. How exactly are you changing the connection parameters and why?
@B-Galati does this fix your issue by any chance?
@dmaicher yes it does! I had the same use case than @julienfalque ;-)
That's amazing! Thank you very much.
I still think that another parameter to differentiate static connection from transactional behavior would be more accurate in terms of semantic. But not sure it's useful :+1:
Hello!
Would it possible to disable static connection but still leverage the transactional behavior?
That may be not easy as it is certainly a BC-break of the behavior of
StaticDriver
.My scenario is that I am changing the connection parameters just before running a test; so at runtime so the connection is not really changed behind the scene.
Cheers!