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

Possible regression from v8.0.2 to v8.1.0 #301

Closed SirTomme closed 1 month ago

SirTomme commented 1 month ago

Hello @dmaicher, I think there was a regression of some kind between v8.0.2 and v8.1.0.

Today I realized that rollbacks were not working after a composer update. I could boil it down to the fact that with composer require --dev dama/doctrine-test-bundle:8.0.2 (as before) everything works great and with composer require --dev dama/doctrine-test-bundle:8.1.0 it does not. Nothing else changed in the project.

As you suggested before here I checked if $connections is populated. I placed a simple dump(self::$connections); in \DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::rollBack(). With both versions the function is being called but with 8.0.2 it dumps my PDO/sqlite connection and with 8.1.0 it dumps an empty array.

With 8.0.2

Created database C:\Users\xxxxxx/var/test.sqlite for connection named default
   > purging database
   > loading App\DataFixtures\AutomationFixtures
PHPUnit 10.5.17 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.12
Configuration: C:\Users\xxxxxx\phpunit.xml.dist

^ array:1 [
  "bc2d4712f1bec316cdae0308c635afa23f97xxxx" => Doctrine\DBAL\Driver\PDO\Connection^ {#1007
    -connection: PDO {#1006
      inTransaction: true
      attributes: {
        CASE: NATURAL
        ERRMODE: EXCEPTION
        PERSISTENT: false
        DRIVER_NAME: "sqlite"
        ORACLE_NULLS: NATURAL
        CLIENT_VERSION: "3.36.0"
        SERVER_VERSION: "3.36.0"
        STATEMENT_CLASS: array:1 [
          0 => "PDOStatement"
        ]
        DEFAULT_FETCH_MODE: BOTH
      }
    }
  }
]
.                                                                   1 / 1 (100%)

With 8.1.0

Same but just dumping []

StaticDriver::connect is called and returns with the first statement:

        if (!self::isKeepStaticConnections() || !isset($params['dama.connection_key'])) {
            return parent::connect($params);
        }

⚠️This is not the case with 8.0.2 were it runs to the end of connect() and returns a new StaticConnection($connection, $platform)

Originally posted by @SirTomme in https://github.com/dmaicher/doctrine-test-bundle/issues/284#issuecomment-2163000082

This is my DBAL config:

doctrine:
    dbal:
        default_connection: default
        types:
            datetimeutc: App\Doctrine\DBAL\Types\DateTimeUtcType
            boolchar_tf: App\Doctrine\DBAL\Types\BoolCharTfType
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
                mapping_types:
                    enum: string
            # This is an OCI8 connection only used in prod, not relevant for the test env I encountered the problems in:
            someoci8:
                # If you want to have an extra platform service:
                # platform_service: App\Doctrine\DBAL\Platforms\SomePlatform
                driver: oci8
                # ...
    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                naming_strategy: doctrine.orm.naming_strategy.default
                auto_mapping: true
                mappings:
                    Default:
                        is_bundle: false
                        type: attribute
                        dir: '%kernel.project_dir%/src/Entity/Default'
                        prefix: 'App\Entity\Default'
                        alias: Default
            someoci8:
                connection: someoci8
                # ...

when@test:
    doctrine:
        dbal:
            connections:
                default:
                    # "TEST_TOKEN" is typically set by ParaTest
                    dbname_suffix: '_test%env(default::TEST_TOKEN)%'
                    # https://github.com/dmaicher/doctrine-test-bundle?tab=readme-ov-file#how-to-install-and-use-this-bundle
                    use_savepoints: true

Nothing special there, I think but I am using the doctrine/doctrine-fixtures-bundle:^3.5.

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['dev' => true],
    Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
    DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
];

I try to create a minimal Repo that reproduces the bug but this may take some days.

dmaicher commented 1 month ago

Are you using paratest? Is it maybe related to that?

SirTomme commented 1 month ago

No I'm not using paratest. That TEST_TOKEN entry is put there by the default installation and I just left it there for the future me ;)

SirTomme commented 1 month ago

Okay the issue can be closed 🙈

I am running some WebTestCases with static::createClient(['debug' => false]) for better performance but missed to clear the cache for env=test after updating the packages.