From 70a2d8c11262b64ea6b22251c99cb25b9ec2b62b Mon Sep 17 00:00:00 2001 From: xjm Date: Sun, 17 Jul 2016 11:55:48 +0200 Subject: [PATCH] Issue #2491033 by daffie, mgifford, dawehner: Return value of Database::getLog() is inconsistent -- always return an array, even when empty --- core/lib/Drupal/Core/Database/Database.php | 2 +- .../Drupal/KernelTests/Core/Database/LoggingTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index e1a5c2a9589..8fe1c453eab 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -129,7 +129,7 @@ abstract class Database { */ final public static function getLog($logging_key, $key = 'default') { if (empty(self::$logs[$key])) { - return NULL; + return []; } $queries = self::$logs[$key]->get($logging_key); self::$logs[$key]->end($logging_key); diff --git a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php index f4ee580d94b..c354c8292b5 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php @@ -126,4 +126,13 @@ class LoggingTest extends DatabaseTestBase { $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.'); } + /** + * Tests that getLog with a wrong key return an empty array. + */ + function testGetLoggingWrongKey() { + $result = Database::getLog('wrong'); + + $this->assertEqual($result, [], 'The function getLog with a wrong key returns an empty array.'); + } + }