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 \Drupal\Core\Logger\LoggerChannel[[api-linebreak]] @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.