From 21ff0c87bf382bf6e9d8d71ccd4dd92af4998109 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 22 Feb 2024 09:01:12 +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 | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
index 6a8715246a22..61f51dc81a64 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificTransactionTestBase.php
@@ -896,15 +896,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 with calling it directly.
-    $manager->__destruct();
+    // this impossible to test unless it is called directly.
+    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