dmaicher / doctrine-test-bundle

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

feature: add support for converting exceptions #255

Closed bendavies closed 11 months ago

bendavies commented 11 months ago

This is sort of a regression from v7, where by exception conversion is lost when creating and releasing savepoints.

This is because the transcations handling for savepoints and exception conversion was previously done in Doctrine\DBAL\Connection, but since that's now moved to the StaticConnection, exception handling needs to be done there.

dmaicher commented 11 months ago

Regarding a test: I think this should work? inside the functional PhpunitTest

    public function testWillThrowSpecificExceptionOnRollback(): void
    {
        $this->expectException(\Doctrine\DBAL\Exception\DriverException::class);
        $this->connection->beginTransaction();
        $this->connection->executeQuery('TRUNCATE TABLE test');
        $this->connection->rollBack();
    }
dmaicher commented 11 months ago

@bendavies actually I'm not sure I can reproduce the issue.

I disabled the bundle and ran the test case mentioned above:

There was 1 failure:

1) Tests\Functional\PhpunitTest::testWillThrowSpecificExceptionOnRollback
Failed asserting that exception of type "Doctrine\DBAL\Driver\PDO\PDOException" matches expected exception "Doctrine\DBAL\Exception\DriverException". Message was: "There is no active transaction" at
/var/www/doctrine-test-bundle/vendor/doctrine/dbal/src/Driver/PDO/Connection.php:130
/var/www/doctrine-test-bundle/vendor/doctrine/dbal/src/Driver/Middleware/AbstractConnectionMiddleware.php:86
/var/www/doctrine-test-bundle/vendor/doctrine/dbal/src/Logging/Connection.php:80
/var/www/doctrine-test-bundle/vendor/doctrine/dbal/src/Driver/Middleware/AbstractConnectionMiddleware.php:86
/var/www/doctrine-test-bundle/vendor/symfony/doctrine-bridge/Middleware/Debug/Connection.php:134
/var/www/doctrine-test-bundle/vendor/doctrine/dbal/src/Connection.php:1514
/var/www/doctrine-test-bundle/tests/Functional/PhpunitTest.php:135

its the same exception class that is also thrown when activating the bundle.

Do you have an example where this currently throws the wrong (not converted) exception?

bendavies commented 11 months ago

I'll take a look later! Our setup might be a bit funky.

dmaicher commented 11 months ago

Closing for now. Let me know if there is a way to reproduce the issue