Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on multiple connections #284

Closed
jmariller opened this issue Feb 23, 2024 · 11 comments
Closed

Not working on multiple connections #284

jmariller opened this issue Feb 23, 2024 · 11 comments

Comments

@jmariller
Copy link

Hi @dmaicher ,

First of all thanks a lot for this bundle, I have a project with a single connection where it works perfectly and it helps us work without worrying about DB conflicts 🙂

Now I am trying to use the bundle on another project which has multiple connections, and although I do not see/get any error message data is not rolled back after each test. I have properly set use_savepoints on all connections as I am using dbal 3.8.

Do you have any idea why this is not working? Let me know which Information could help you, as I am not able to share a repository since this is a big project.

Many thanks in advance for your support.

@dmaicher
Copy link
Owner

I'm using this bundle myself on a project with 2 connections and it works fine.

Can you reproduce the issue on a small project and provide a repository?

@dmaicher
Copy link
Owner

dmaicher commented Mar 2, 2024

Closing this for now. Let me know in case you can provide a reproducer.

@dmaicher dmaicher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2024
@jmariller
Copy link
Author

jmariller commented Mar 2, 2024 via email

@jmariller
Copy link
Author

Hi @dmaicher so I did a few more tests and realized it has nothing to do with the multiple connections: when I keep only the default connection and try again, the same behaviour occurs. I even tried to copy the content of doctrine.yaml from that project mentioned above where it works to the one where it doesn't, without any success. How could I debug this further, since I do not get any error message? Thank you 🙏

@dmaicher
Copy link
Owner

dmaicher commented Mar 5, 2024

I would start by checking if the connection is kept inside DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver::$connections and what exactly happens there on rollBack() and if its called by the phpunit extension

@jmariller
Copy link
Author

Thanks for your help & patience @dmaicher so I did as you proposed and found out that $connections is actually empty! The rollback method is indeed called however when reaching the for loop around connections it does nothing because of the empty array 🤔 any further idea what could be the cause?

@dmaicher
Copy link
Owner

dmaicher commented Mar 6, 2024

Then maybe check next why StaticDriver::$connections is not populated. Is DAMA\DoctrineTestBundle\Doctrine\DBAL\Middleware registered and invoked? So is the StaticDriver used?

@jmariller
Copy link
Author

jmariller commented Mar 7, 2024

The Middleware seems to be properly registered and invoked (and so is the StaticDriver used, got it confirmed via some var_dumps), however the method StaticDriver::connect is never called 😕 Here is the dummy test I am working with:

<?php

namespace App\Tests\Entity;

use App\Entity\Brand;
use Faker\Factory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class BrandTest extends KernelTestCase
{
  public function testCreateBrand(): void
  {
    $faker = Factory::create();

    $brand = (new Brand())
        ->setName($faker->regexify('[A-Z]{10}'))
        ->setSlug($faker->slug())
    ;

    $manager = static::getContainer()->get('doctrine')->getManager();

    $manager->persist($brand);
    $manager->flush();
  }
}

@dmaicher
Copy link
Owner

dmaicher commented Mar 7, 2024

Then I'm afraid you need to find out why StaticDriver::connect is not called

@SirTomme
Copy link

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)

@dmaicher
Copy link
Owner

@SirTomme can you please open a new issue? also with more details on the Doctrine DBAL config or how to reproduce that issue please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants