Issue #2491033 by daffie, mgifford, dawehner: Return value of Database::getLog() is inconsistent -- always return an array, even when empty

8.2.x
xjm 2016-07-17 11:55:48 +02:00
parent 8e04ab6b7f
commit 70a2d8c112
2 changed files with 10 additions and 1 deletions

View File

@ -129,7 +129,7 @@ abstract class Database {
*/ */
final public static function getLog($logging_key, $key = 'default') { final public static function getLog($logging_key, $key = 'default') {
if (empty(self::$logs[$key])) { if (empty(self::$logs[$key])) {
return NULL; return [];
} }
$queries = self::$logs[$key]->get($logging_key); $queries = self::$logs[$key]->get($logging_key);
self::$logs[$key]->end($logging_key); self::$logs[$key]->end($logging_key);

View File

@ -126,4 +126,13 @@ class LoggingTest extends DatabaseTestBase {
$this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.'); $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.');
}
} }