diff --git a/core/includes/database.inc b/core/includes/database.inc index ae9533c7dc7..04132b81e78 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -464,6 +464,7 @@ function db_close(array $options = []) { * @see https://www.drupal.org/node/2993033 */ function _db_get_target(array &$options, $allow_replica = TRUE) { + @trigger_error('_db_get_target() is deprecated in drupal:8.8.0. Will be removed before drupal:9.0.0. See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); if (empty($options['target']) || ($options['target'] === 'replica' && !$allow_replica)) { $options['target'] = 'default'; } diff --git a/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php index f9b7f02256b..9fa3fc02246 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php @@ -530,4 +530,17 @@ class DatabaseLegacyTest extends DatabaseTestBase { $this->assertTrue($session->has('ignore_replica_server')); } + /** + * Tests the _db_get_target() function. + * + * @expectedDeprecation _db_get_target() is deprecated in drupal:8.8.0. Will be removed before drupal:9.0.0. See https://www.drupal.org/node/2993033 + */ + public function testDbGetTarget() { + $op1 = $op2 = ['target' => 'replica']; + $this->assertEquals('replica', _db_get_target($op1)); + $this->assertEquals('default', _db_get_target($op2, FALSE)); + $this->assertEmpty($op1); + $this->assertEmpty($op2); + } + }