From df0d8ea5756f7b8e0483ffb49aecbbfbb59e1e3c Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 22 Feb 2024 08:59:57 +0000
Subject: [PATCH] Issue #3405976 by alexpott, jrglasgow, fago, catch, mondrake,
 solideogloria, mglaman, Driskell, derickr, longwave, Mile23, YesCT, daffie:
 Transaction autocommit during shutdown relies on unreliable object
 destruction order (xdebug 3.3+ enabled)

---
 .../Database/DriverSpecificTransactionTestBase.php   | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
index c3f7275f7f73..e6bb2f0786f7 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
@@ -818,15 +818,21 @@ public function testTransactionManagerFailureOnPendingStackItems(): void {
     $reflectionProperty = new \ReflectionProperty(TransactionManagerBase::class, 'connectionTransactionState');
     $reflectionProperty->setValue($manager, ClientConnectionTransactionState::Active);
 
-    $this->expectException(\AssertionError::class);
-    $this->expectExceptionMessageMatches("/^Transaction .stack was not empty\\. Active stack: bar\\\\qux/");
     // Ensure that __destruct() results in an assertion error. Note that this
     // will normally be called by PHP during the object's destruction but Drupal
     // will commit all transactions when a database is closed thereby making
     // this impossible to test unless it is called directly.
-    $manager->__destruct();
+    try {
+      $manager->__destruct();
+      $this->fail("Expected AssertionError error not thrown");
+    }
+    catch (\AssertionError $e) {
+      $this->assertStringStartsWith('Transaction $stack was not empty. Active stack: bar\\qux', $e->getMessage());
+    }
 
     // Clean up.
+    $reflectionProperty = new \ReflectionProperty(TransactionManagerBase::class, 'stack');
+    $reflectionProperty->setValue($manager, []);
     unset($testConnection);
     Database::closeConnection('test_fail');
   }
-- 
GitLab