Problem/Motivation

In 10.1.x my unit tests for entity_hierarchy work. In 10.2.x I get the following error.
This is because the database info for 'driver' as returned by Database::getAllConnectionInfo() is now a class name.

1) Drupal\Tests\entity_hierarchy\Functional\DeleteParentWarningTest::testDeleteWarning
Doctrine\DBAL\Exception: The given 'driver' pdo_Drupal\mysql\Driver\Database\mysql is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_sqlsrv, mysqli, drizzle_pdo_mysql, sqlanywhere, sqlsrv

/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:138
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php:296
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php:250
/var/www/html/modules/contrib/dbal/src/ConnectionFactory.php:78
/var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php:255
/var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php:177
/var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php:440
/var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php:237
/var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php:177
/var/www/html/modules/contrib/entity_hierarchy/tests/src/Traits/EntityHierarchyTestTrait.php:55
/var/www/html/modules/contrib/entity_hierarchy/tests/src/Functional/DeleteParentWarningTest.php:43
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Steps to reproduce

Get 10.2.x and use ConnectionFactory to get a database connection.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nterbogt created an issue. See original summary.

larowlan’s picture

So this isn't an issue on 10.1?

larowlan’s picture

If so I think we can use the new BC layer - https://www.drupal.org/node/3379306 if we make the code to derive the pdo class an anonymous function

larowlan’s picture

Hmm I'm seeing this in the connection factory


if (empty($info['namespace']) || str_starts_with($info['namespace'], 'Drupal\\Core\\Database\\Driver\\')) {
      switch (strtolower($info['driver'])) {
        case 'mysql':
          $info['namespace'] = 'Drupal\\mysql\\Driver\\Database\\mysql';
          break;

        case 'pgsql':
          $info['namespace'] = 'Drupal\\pgsql\\Driver\\Database\\pgsql';
          break;

        case 'sqlite':
          $info['namespace'] = 'Drupal\\sqlite\\Driver\\Database\\sqlite';
          break;
      }
    }

which seems to indicate they're still string
🤔

ansergeyg’s picture

I confirm we have the same issue in our unit tests. We use different db drivers in our project. And after upgrading to 10.2.1, test that use different dib drivers are no longer working in our project. Would be nice to give it a priority or provide a fix. In our case sparql driver doesn't work anymore.

Regards

larowlan’s picture

Is this test specific?
I've seen it in tests but can't find the source of it

larowlan’s picture

https://git.drupalcode.org/project/entity_hierarchy/-/jobs/630574 showing a failing test for entity_hierarchy with this issue

larowlan’s picture

Status: Active » Needs review
FileSize
1.22 KB

Its ugly, but something like this?

  • larowlan committed e3bf17ee on 2.x
    Issue #3400406 by larowlan, nterbogt, ansergeyg: Driver is class name in...

  • larowlan committed 805724b4 on 8.x-1.x
    Issue #3400406 by larowlan, nterbogt, ansergeyg: Driver is class name in...
larowlan’s picture

Version: 2.0.0 » 8.x-1.x-dev
Status: Needs review » Fixed

Committed to 8.x-1.x and c/p to 2.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.