dmaicher / doctrine-test-bundle

Symfony bundle to isolate your app's doctrine database tests and improve the test performance
MIT License
1.08k stars 61 forks source link

How to detect dama wrapper is active ? #295

Closed Kytrix closed 4 months ago

Kytrix commented 4 months ago

Hello, I previously used a test inside my ancestor test class constructor: if(!$this->em->getConnection()->isTransactionActive()) $this->fail("No active transaction ! you could lost data !\n");

But it seems to not work with lasts versions.

I made another test by looking in Connection params.

I try to get the driver class, but because the wrapperDriver is private I'm not able to test it's class, despite my debugger is able to see it : image

Is there a better solution ?

dmaicher commented 4 months ago

Out of curiosity: why would you need to detect if the bundle is managing a connection? :thinking:

Kytrix commented 4 months ago

Because I already have the issue of the tests were running without transaction (the bundle was somehow been disabled) and I don't want this could append again.

dmaicher commented 4 months ago

You could try


/** @var \PDO $connection */
$connection = $this->em->getConnection()->getNativeConnection();
if(!$connection->inTransaction()) {
    $this->fail("No active transaction ! you could lost data !\n");
}
Kytrix commented 4 months ago

Thank you very much ! it works !