dmaicher / doctrine-test-bundle

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

Deprecation: Subscribing to `postConnect` events is deprecated. Implement a middleware instead. #248

Closed ruudk closed 1 year ago

ruudk commented 1 year ago

First of all, thanks for this amazing bundle 💙

It seems that it's using a postConnect listener that is being deprecated.

We were using the postConnect listener too in our project and we solved it by using a middleware like this:

<?php

final readonly class DriverMiddleware implements Middleware
{
    public function wrap(DriverInterface $driver) : DriverInterface
    {
        return new MyDriver($driver);
    }
}

final class MyDriver extends AbstractDriverMiddleware
{
    public function connect(
        #[SensitiveParameter]
        array $params,
    ) : DriverConnection {
        $connection = parent::connect($params);
        // do post connect

        return $connection;
    }
}

Do you think this could be a solution? If so, I could try to create a PR. But you probably know better if it could work or not.

dmaicher commented 1 year ago

see the latest 8.0 Beta release 😉 please test it

ruudk commented 1 year ago

Wow., didn't know.

I just ran it on our large functional test suite (±2000 tests split over 3 jobs) and it works great.

The deprecation is gone, but a new one appeared:

Nesting transactions without enabling savepoints is deprecated.
Call Doctrine\DBAL\Connection::setNestTransactionsWithSavepoints(true) to enable savepoints. (Connection.php:1373 called by UnitOfWork.php:415, https://github.com/doctrine/dbal/pull/5383, package doctrine/dbal)
dmaicher commented 1 year ago

For this deprecation you should configure use_savepoints: true on the dbal connection. See https://github.com/dmaicher/doctrine-test-bundle/blob/master/tests/Functional/app/config.yml#L12 for example.

ruudk commented 1 year ago

That did the trick. Thanks for pointing me towards that.

So to summarize, 8.0 Beta 1 rocks! So glad that the previous deprecation (VersionAware) is gone now. Really happy with that.

+1 for 8.0 GM 😉

dmaicher commented 1 year ago

Nice! Thanks for the feedback. I will think about actually making use_savepoints: true a requirement for 8.0. It does not make sense to use the bundle without enabling it.

Apart from that waiting a bit longer to see if there are more breaking changes with DBAL 4 that I could address in 8.0