You are here

public function LoggerChannelTest::testLog in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 38
Contains \Drupal\Tests\Core\Logger\LoggerChannelTest.

Class

LoggerChannelTest
@coversDefaultClass \Drupal\Core\Logger\LoggerChannel @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
    ->getMock('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);
}