function LoggerChannelTest::testSortLoggers

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::testSortLoggers()
  2. 8.9.x core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php \Drupal\Tests\Core\Logger\LoggerChannelTest::testSortLoggers()
  3. 11.x 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 91

Class

LoggerChannelTest
@coversDefaultClass \Drupal\Core\Logger\LoggerChannel[[api-linebreak]] @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function testSortLoggers() : void {
  $channel = new LoggerChannel($this->randomMachineName());
  $index_order = '';
  for ($i = 0; $i < 4; $i++) {
    $logger = $this->createMock('Psr\\Log\\LoggerInterface');
    $logger->expects($this->once())
      ->method('log')
      ->willReturnCallback(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('3210', $index_order);
}

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