function LoggingTest::testContribDriverLog

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php \Drupal\KernelTests\Core\Database\LoggingTest::testContribDriverLog()

Tests that a log called by a custom database driver returns proper caller.

@covers ::findCaller

@dataProvider providerContribDriverLog

@group legacy

Parameters

string $driver_namespace: The driver namespace to be tested.

string $stack: A test debug_backtrace stack.

array $expected_entry: The expected stack entry.

File

core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php, line 162

Class

LoggingTest
Tests the query logging facility.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testContribDriverLog($driver_namespace, $stack, array $expected_entry) : void {
    $this->expectDeprecation('Drupal\\Core\\Database\\Log::findCaller() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::findCallerFromDebugBacktrace(). See https://www.drupal.org/node/3328053');
    $this->expectDeprecation('Drupal\\Core\\Database\\Log::removeDatabaseEntries() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::removeDatabaseEntriesFromDebugBacktrace(). See https://www.drupal.org/node/3328053');
    $mock_builder = $this->getMockBuilder(Log::class);
    $log = $mock_builder->onlyMethods([
        'getDebugBacktrace',
    ])
        ->setConstructorArgs([
        'test',
    ])
        ->getMock();
    $log->expects($this->once())
        ->method('getDebugBacktrace')
        ->willReturn($stack);
    Database::addConnectionInfo('test', 'default', [
        'driver' => 'mysql',
        'namespace' => $driver_namespace,
    ]);
    $result = $log->findCaller($stack);
    $this->assertEquals($expected_entry, $result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.