diff --git a/core/lib/Drupal/Core/Database/Log.php b/core/lib/Drupal/Core/Database/Log.php index f56ed68..7a014cc 100644 --- a/core/lib/Drupal/Core/Database/Log.php +++ b/core/lib/Drupal/Core/Database/Log.php @@ -146,12 +146,12 @@ public function findCaller() { $stack = $this->getDebugBacktrace(); // Drop all stack entries before and including methods called from the - // database connection class. - $connection_class = $this->getConnectionClass(); - while (count($stack) > 2 && (!empty($stack[0]['class']) ? $stack[0]['class'] : '') !== $connection_class) { + // database connection namespace. + $connection_namespace = $this->getConnectionNamespace(); + while (count($stack) > 2 && strpos((!empty($stack[0]['class']) ? $stack[0]['class'] : ''), $connection_namespace) === FALSE) { array_shift($stack); } - while (count($stack) > 2 && (!empty($stack[0]['class']) ? $stack[0]['class'] : '') === $connection_class) { + while (count($stack) > 2 && strpos((!empty($stack[0]['class']) ? $stack[0]['class'] : ''), $connection_namespace) === 0) { array_shift($stack); } @@ -177,13 +177,13 @@ public function findCaller() { } /** - * Gets the class name of the database connection. + * Gets the namespace of the database connection. * * @return string - * Fully qualified class name of the database connection. + * Namespace of the database connection. */ - protected function getConnectionClass() { - return get_class(Database::getConnection($this->connectionKey)); + protected function getConnectionNamespace() { + return (new \ReflectionObject(Database::getConnection($this->connectionKey)))->getNamespaceName(); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php index b4e3773..47f48e0 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php @@ -140,8 +140,8 @@ public function testGetLoggingWrongKey() { /** * Tests that a log called by a custom database driver returns proper caller. * - * @param string $connection_class - * The connection class to be tested. + * @param string $connection_namespace + * The connection namespace to be tested. * @param array $expected_entry * The expected stack entry. * @@ -149,7 +149,7 @@ public function testGetLoggingWrongKey() { * * @dataProvider providerContribDriverLog */ - public function testContribDriverLog($connection_class, array $expected_entry) { + public function testContribDriverLog($connection_namespace, array $expected_entry) { $stack = [ [ 'file' => '/var/www/core/lib/Drupal/Core/Database/Log.php', @@ -259,11 +259,11 @@ public function testContribDriverLog($connection_class, array $expected_entry) { $mock_builder = $this->getMockBuilder(Log::class); $log = $mock_builder - ->setMethods(['getConnectionClass', 'getDebugBacktrace']) + ->setMethods(['getConnectionNamespace', 'getDebugBacktrace']) ->getMock(); $log->expects($this->once()) - ->method('getConnectionClass') - ->will($this->returnValue($connection_class)); + ->method('getConnectionNamespace') + ->will($this->returnValue($connection_namespace)); $log->expects($this->once()) ->method('getDebugBacktrace') ->will($this->returnValue($stack)); @@ -277,7 +277,7 @@ public function testContribDriverLog($connection_class, array $expected_entry) { * * @return array[] * A simple array of simple arrays, each having the following elements: - * - the contrib driver Connection class fully qualified name + * - the contrib driver Connection class namespace * - the stack entry expected to be returned. * * @see ::testContribDriverLog() @@ -287,7 +287,7 @@ public function providerContribDriverLog() { // Test that if the driver Connection is in the stack trace, the first // non-database entry is returned. [ - 'Drupal\\Driver\\Database\\dbal\\Connection', + 'Drupal\\Driver\\Database\\dbal', [ 'class' => 'Drupal\\KernelTests\\Core\\Database\\LoggingTest', 'function' => 'testEnableLogging', @@ -298,9 +298,9 @@ public function providerContribDriverLog() { ] ], // Test that if the driver Connection is not in the stack trace, the very - // first backtrace entry is returned. + // last backtrace entry is still returned. [ - 'Drupal\\Driver\\Database\\fake\\Connection', + 'Drupal\\Driver\\Database\\fake', [ 'file' => '-', 'line' => 52,