diff --git a/core/lib/Drupal/Core/Database/Log.php b/core/lib/Drupal/Core/Database/Log.php index eac37d5..32cf4e7 100644 --- a/core/lib/Drupal/Core/Database/Log.php +++ b/core/lib/Drupal/Core/Database/Log.php @@ -135,7 +135,7 @@ public function log(StatementInterface $statement, $args, $time) { * function. * * @param array $stack - * (optional) The backtrace to find the caller in. It falls back to the + * (optional) The backtrace to find the caller in. It falls back to the * current backtrace. * * @return diff --git a/core/tests/Drupal/KernelTests/Core/Database/LogTest.php b/core/tests/Drupal/KernelTests/Core/Database/LogTest.php deleted file mode 100644 index 61b3a6d..0000000 --- a/core/tests/Drupal/KernelTests/Core/Database/LogTest.php +++ /dev/null @@ -1,124 +0,0 @@ - 'Drupal\Core\Database\Log', - 'function' => 'findCaller', - 'file' => 'core/lib/Drupal/Core/Database/Log.php', - 'line' => 1, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Drupal\Core\Database\Log', - 'function' => 'log', - 'file' => 'core/lib/Drupal/Core/Database/Log.php', - 'line' => 0, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Drupal\Core\Database\Statement', - 'function' => 'execute', - 'file' => 'core/lib/Drupal/Core/Database/Statement.php', - 'line' => 0, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Doctrine\DBAL\Statement', - 'function' => 'execute', - 'file' => 'vendor/doctrine/dbal/Statement.php', - 'line' => 0, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Drupal\Driver\Database\dbal\Connection', - 'function' => 'execute', - 'file' => 'modules/dbal/Drupal/Driver/Database/dbal/Connection.php', - 'line' => 0, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'function' => 'db_query', - 'file' => 'core/includes/database.inc', - 'line' => 56, - 'type' => '::', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Drupal\drudbal\Tests\LoggingTest', - 'function' => 'testEnableLogging', - 'file' => 'modules/dbal/tests/LoggingTest.php', - 'line' => 11, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'class' => 'Drupal\simpletest\TestBase', - 'function' => 'run', - 'file' => 'core/modules/simpletest/src/TestBase.php', - 'line' => 861, - 'type' => '->', - 'args' => [], - ]; - $stack[] = [ - 'function' => '_simpletest_batch_operation', - 'file' => 'core/modules/simpletest/simpletest.module', - 'line' => 398, - 'type' => '::', - 'args' => [], - ]; - $stack[] = [ - 'function' => '_batch_process', - 'file' => 'core/includes/batch.inc', - 'line' => 209, - 'type' => '::', - 'args' => [], - ]; - $stack[] = [ - 'function' => '_batch_do', - 'file' => 'core/includes/batch.inc', - 'line' => 93, - 'type' => '::', - 'args' => [], - ]; - $stack[] = [ - 'function' => '_batch_page', - 'file' => 'core/includes/batch.inc', - 'line' => 34, - 'type' => '::', - 'args' => [], - ]; - - $result = $log->findCaller($stack); - $expected_result = [ - 'class' => 'Drupal\drudbal\Tests\LoggingTest', - 'function' => 'testEnableLogging', - 'file' => 'modules/dbal/tests/LoggingTest.php', - 'line' => 11, - 'type' => '->', - 'args' => [], - ]; - $this->assertEquals($expected_result, $result); - } - -} diff --git a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php index 0216d3e..225065a 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php @@ -2,11 +2,13 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Core\Database\Log; use Drupal\Core\Database\Database; /** * Tests the query logging facility. * + * @coversDefaultClass \Drupal\Core\Database\Log * @group Database */ class LoggingTest extends DatabaseTestBase { @@ -135,4 +137,131 @@ public function testGetLoggingWrongKey() { $this->assertEqual($result, [], 'The function getLog with a wrong key returns an empty array.'); } + /** + * Tests that a log called by a custom database driver return proper caller. + * + * @covers ::findCaller + */ + public function testContribDriverLog() { + $log = new Log('default'); + + $stack = [ + [ + 'file' => '/var/www/core/lib/Drupal/Core/Database/Log.php', + 'line' => 118, + 'function' => 'findCaller', + 'class' => 'Drupal\\Core\\Database\\Log', + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/core/lib/Drupal/Core/Database/Statement.php', + 'line' => 63, + 'function' => 'log', + 'class' => 'Drupal\\Core\\Database\\Log', + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php', + 'line' => 168, + 'function' => 'execute', + 'class' => 'Drupal\\Core\\Database\\Statement', + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/modules/contrib/drudbal/drivers/lib/Drupal/Driver/Database/dbal/Connection.php', + 'line' => 183, + 'function' => 'execute', + 'class' => 'Doctrine\\DBAL\\Statement', + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/core/includes/database.inc', + 'line' => 61, + 'function' => 'query', + 'class' => 'Drupal\\Driver\\Database\\dbal\\Connection', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/tests/Drupal/KernelTests/Core/Database/LoggingTest.php', + 'line' => 20, + 'function' => 'db_query', + 'args' => [], + ], + [ + 'class' => 'Drupal\\KernelTests\\Core\\Database\\LoggingTest', + 'function' => 'testEnableLogging', + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/vendor/phpunit/phpunit/src/Framework/TestCase.php', + 'line' => 908, + 'function' => 'invokeArgs', + 'class' => 'ReflectionMethod', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/vendor/phpunit/phpunit/src/Framework/TestCase.php', + 'line' => 768, + 'function' => 'runTest', + 'class' => 'PHPUnit_Framework_TestCase', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/vendor/phpunit/phpunit/src/Framework/TestResult.php', + 'line' => 612, + 'function' => 'runBare', + 'class' => 'PHPUnit_Framework_TestCase', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '/var/www/vendor/phpunit/phpunit/src/Framework/TestCase.php', + 'line' => 724, + 'function' => 'run', + 'class' => 'PHPUnit_Framework_TestResult', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '-', + 'line' => 52, + 'function' => 'run', + 'class' => 'PHPUnit_Framework_TestCase', + 'object' => NULL, + 'type' => '->', + 'args' => [], + ], + [ + 'file' => '-', + 'line' => 1574, + 'function' => '__phpunit_run_isolated_test', + 'args' => [], + ], + ]; + + $result = $log->findCaller($stack); + $expected_result = [ + 'class' => 'Drupal\\KernelTests\\Core\\Database\\LoggingTest', + 'function' => 'testEnableLogging', + 'file' => '/var/www/tests/Drupal/KernelTests/Core/Database/LoggingTest.php', + 'line' => 20, + 'type' => '->', + 'args' => [], + ]; + $this->assertEquals($expected_result, $result); + } + }