You are here

public function LoggerChannelTest::testSortLoggers 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::testSortLoggers()

Tests LoggerChannel::addLoggers().

@covers ::addLogger @covers ::sortLoggers

File

core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php, line 63
Contains \Drupal\Tests\Core\Logger\LoggerChannelTest.

Class

LoggerChannelTest
@coversDefaultClass \Drupal\Core\Logger\LoggerChannel @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function testSortLoggers() {
  $channel = new LoggerChannel($this
    ->randomMachineName());
  $index_order = '';
  for ($i = 0; $i < 4; $i++) {
    $logger = $this
      ->getMock('Psr\\Log\\LoggerInterface');
    $logger
      ->expects($this
      ->once())
      ->method('log')
      ->will($this
      ->returnCallback(function () use ($i, &$index_order) {

      // Append the $i to the index order, so that we know the order that
      // loggers got called with.
      $index_order .= $i;
    }));
    $channel
      ->addLogger($logger, $i);
  }
  $channel
    ->log(rand(0, 7), $this
    ->randomMachineName());

  // Ensure that the logger added in the end fired first.
  $this
    ->assertEquals($index_order, '3210');
}