As of Drupal 8.9, contrib database drivers are allowed to reside within a module. The KernelTestBase ensures that the main bootstrap.inc file Is included for kernel tests. One of the functions in the bootstrap is called when contrib drivers connection namespace is being resolved by core. This moving the call to parent::setup() to the top of the test’s setup.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Beakerboy created an issue. See original summary.

Beakerboy’s picture

daffie’s picture

Status: Active » Reviewed & tested by the community

The code of this patch comes from my own patch from #3128699: Testing issue for pgsql_fallback.

Beakerboy’s picture

Assigned: Beakerboy » Unassigned
alexpott’s picture

Beakerboy’s picture

@alexpott No, that causes massive, across the board failures:

Drupal\KernelTests\Core\Database\SelectSubqueryTest::testFromSubquerySelect
Error: Call to undefined function Drupal\Core\drupal_valid_test_ua()

/home/travis/build/Beakerboy/drupal-project/core/lib/Drupal/Core/DrupalKernel.php:378
/home/travis/build/Beakerboy/drupal-project/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php:190
/home/travis/build/Beakerboy/drupal-project/core/lib/Drupal/Core/Database/Database.php:582
/home/travis/build/Beakerboy/drupal-project/core/lib/Drupal/Core/Database/Database.php:483
/home/travis/build/Beakerboy/drupal-project/core/tests/Drupal/KernelTests/KernelTestBase.php:436
1351/home/travis/build/Beakerboy/drupal-project/core/tests/Drupal/KernelTests/KernelTestBase.php:260
/home/travis/build/Beakerboy/drupal-project/core/tests/Drupal/KernelTests/KernelTestBase.php:240
/home/travis/build/Beakerboy/drupal-project/core/tests/Drupal/KernelTests/Core/Database/DatabaseTestBase.php:26
/home/travis/build/Beakerboy/drupal-project/vendor/phpunit/phpunit/src/Framework/TestResult.php:691

alexpott’s picture

@Beakerboy did you remove vendor and do a composer install... #6 looks like you did not.

Edit: I think you only need to run composer install again to rebuild the autoloader.

Beakerboy’s picture

I have a bash script where I list all the patches that need to be applied for the repository. It runs that after the composer install. After applying this patch earlier in my sequence instead, before the composer install, the remaining "Call to undefined function Drupal\Core\drupal_valid_test_ua()" Errors are gone. However, your patch is for D9 while this is for D8.9. Thanks.

alexpott’s picture

@Beakerboy so #8 didn't make it clear whether #3151118: Include bootstrap.inc using composer did actually fix this issue. Does it?

Beakerboy’s picture

Drupal 9 has fewer "Call to undefined function Drupal\Core\drupal_valid_test_ua()" errors than D8.9. Your patch fixes the leftovers that were not fixed by some other means.

This patch is for D8 though.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Indeed and we need a D9 version of this first - this needs to land in 9.1.x and 9.0.x too.

Beakerboy’s picture

Are planning on porting your patch to Drupal 8.9? If so, that would render this issue here moot and it could be closed, right?

daffie’s picture

Issue tags: +Needs reroll

Needs an reroll for 9.1 and 9.0.

Beakerboy’s picture

When I said “some other means” in #10, I was not referring to “this” issue. There is some unknown-to-me reason that fixed a bunch of them in D9. I have not ported this simple fix to D9, and I don’t know why I should if the patch by @alexpott is the preferred fix. Can someone please explain why this issue needs to be ported to D9? If the standard protocol is to patch D9.1 and back port previous Drupal versions from there, then great. I just would like to know why this is necessary.

alexpott’s picture

@Beakerboy I think that #3151118: Include bootstrap.inc using composer will only land in 9.1.x - so let's go ahead with this one - and backport to 8.9.x once both patches are ready.

sanjayk’s picture

Assigned: Unassigned » sanjayk
sanjayk’s picture

Reroll the patch for d9.1.0-dev

daffie’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Rerolled for Drupal 9.0 and 9.1.
Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed c71e7e4e57 to 9.1.x and 68cb6a2033 to 9.0.x. Thanks!
Committed d31a8c6 and pushed to 8.9.x. Thanks!

+++ b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
@@ -31,12 +31,14 @@ class EndOfTransactionQueriesTest extends KernelTestBase {
+    // The bootstrap file must be included betore getDatabaseConnectionInfo
+    // for contrib database drivers.

This comment contains a spelling mistake and is not that important here.

So I rewrote it and moved it on commit:

diff --git a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
index 08793d0bb2..1d735d511d 100644
--- a/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
@@ -31,10 +31,10 @@ class EndOfTransactionQueriesTest extends KernelTestBase {
    * {@inheritdoc}
    */
   protected function setUp(): void {
-    // The bootstrap file must be included betore getDatabaseConnectionInfo
-    // for contrib database drivers.
     parent::setUp();
 
+    // This can only be checked after installing Drupal as it requires functions
+    // from bootstrap.inc.
     if (!class_exists($this->getDatabaseConnectionInfo()['default']['namespace'] . '\Connection')) {
       $this->markTestSkipped(sprintf('No logging override exists for the %s database driver. Create it, subclass this test class and override ::getDatabaseConnectionInfo().', $this->getDatabaseConnectionInfo()['default']['driver']));
     }

Because it really applies to the call in the class_exists() check.

  • alexpott committed c71e7e4 on 9.1.x
    Issue #3152003 by Beakerboy, sanjayk, alexpott, daffie:...

  • alexpott committed 68cb6a2 on 9.0.x
    Issue #3152003 by Beakerboy, sanjayk, alexpott, daffie:...

  • alexpott committed d31a8c6 on 8.9.x
    Issue #3152003 by Beakerboy, sanjayk, alexpott, daffie:...

Status: Fixed » Closed (fixed)

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