Error at the end of any PHPunit test

Created on 30 July 2025, 5 days ago

Problem/Motivation

This is exactly the same behavior described in this issue
https://www.drupal.org/project/drupal/issues/3507999 🐛 Error on PHUnit after transaction destruct Active related to 10.4x

When launching phpunit tests that uses databases calls, it ends with a TypeError, basically because Drupal try to do some transaction cleanup at the end of the script execution using a database connection that had already been destroyed by phpunit at the end of its test suite.

Steps to reproduce

Just launch phpunit tests

Proposed resolution

I propose to add a test checking the availability of the database connection before launching the unpile task in the Transaction::__destruct() method in order to avoid errors in that particular case.

API changes

Drupal\Core\Database\Connection

Add a method hasClientConnection() to Drupal\Core\Database\Connection in order to have a mean to know if the object is available or not (regardless of this problem it seems wise to me to have this method)

test of the client's connection avaibility

Implement a test of the connection avaibility using this method either in
Drupal\Core\Database\Transaction::__destruct() method to avoid launching unpile
or more deeper in Drupal\Core\Cache\DatabaseCacheTagsChecksum::doInvalidateTags (which is the where the problem really occurs).

🐛 Bug report
Status

Active

Version

11.2 🔥

Component

database system

Created by

🇫🇷France ceonizm Marseille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024