function LoggerChannelTest::testLog

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

Tests LoggerChannel::log().

@dataProvider providerTestLog @covers ::log @covers ::setCurrentUser @covers ::setRequestStack

Parameters

callable $expected: An anonymous function to use with $this->callback() of the logger mock. The function should check the $context array for expected values.

\Symfony\Component\HttpFoundation\Request $request: Will be passed to the channel under test if present.

\Drupal\Core\Session\AccountInterface $current_user: Will be passed to the channel under test if present.

File

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

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 testLog(callable $expected, Request $request = NULL, AccountInterface $current_user = NULL) {
    $channel = new LoggerChannel('test');
    $message = $this->randomMachineName();
    $logger = $this->createMock('Psr\\Log\\LoggerInterface');
    $logger->expects($this->once())
        ->method('log')
        ->with($this->anything(), $message, $this->callback($expected));
    $channel->addLogger($logger);
    if ($request) {
        $requestStack = new RequestStack();
        $requestStack->push($request);
        $channel->setRequestStack($requestStack);
    }
    if ($current_user) {
        $channel->setCurrentUser($current_user);
    }
    $channel->log(rand(0, 7), $message);
}

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