function LoggerChannelTest::providerTestLog

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::providerTestLog()
  2. 10 core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::providerTestLog()
  3. 11.x core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::providerTestLog()

Data provider for self::testLog().

File

core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php, line 136

Class

LoggerChannelTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Logger%21LoggerChannel.php/class/LoggerChannel/9" title="Defines a logger channel that most implementations will use." class="local">\Drupal\Core\Logger\LoggerChannel</a> @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function providerTestLog() {
    $account_mock = $this->createMock('Drupal\\Core\\Session\\AccountInterface');
    $account_mock->expects($this->any())
        ->method('id')
        ->willReturn(1);
    $request_mock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')
        ->onlyMethods([
        'getClientIp',
    ])
        ->getMock();
    $request_mock->expects($this->any())
        ->method('getClientIp')
        ->willReturn('127.0.0.1');
    $request_mock->headers = $this->createMock('Symfony\\Component\\HttpFoundation\\ParameterBag');
    // No request or account.
    $cases[] = [
        function ($context) {
            return $context['channel'] == 'test' && empty($context['uid']) && $context['ip'] === '';
        },
    ];
    // With account but not request. Since the request is not available the
    // current user should not be used.
    $cases[] = [
        function ($context) {
            return $context['uid'] === 0 && $context['ip'] === '';
        },
        NULL,
        $account_mock,
    ];
    // With request but not account.
    $cases[] = [
        function ($context) {
            return $context['ip'] === '127.0.0.1' && empty($context['uid']);
        },
        $request_mock,
    ];
    // Both request and account.
    $cases[] = [
        function ($context) {
            return $context['ip'] === '127.0.0.1' && $context['uid'] === 1;
        },
        $request_mock,
        $account_mock,
    ];
    return $cases;
}

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