function LoggerChannelTest::providerTestLog

Same name 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 \Drupal\Core\Logger\LoggerChannel @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.