You are here

class LoggerMock in Acquia Content Hub 8.2

Mock Logger created for easy assertions of log messages.

Hierarchy

Expanded class hierarchy of LoggerMock

2 files declare their use of LoggerMock
ImportUpdateAssetsTest.php in tests/src/Kernel/ImportUpdateAssetsTest.php
IsPathAliasForUnpublishedContentTest.php in modules/acquia_contenthub_publisher/tests/src/Unit/EventSubscriber/EntityEligibility/IsPathAliasForUnpublishedContentTest.php

File

tests/src/Unit/Helpers/LoggerMock.php, line 15

Namespace

Drupal\Tests\acquia_contenthub\Unit\Helpers
View source
class LoggerMock implements LoggerChannelInterface {
  use RfcLoggerTrait;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Constructs a LoggerMock object.
   */
  public function __construct() {
    $this->parser = new LogMessageParser();
  }

  /**
   * Log messages.
   *
   * @var array
   */
  protected $logMessages = [];

  /**
   * {@inheritDoc}
   */
  public function log($level, $message, array $context = []) {
    if (!empty($context)) {
      $message_placeholders = $this->parser
        ->parseMessagePlaceholders($message, $context);
      $message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
    }
    $this->logMessages[$level][] = strip_tags($message);
  }

  /**
   * Helper method that can be used for assertions.
   *
   * @return array
   *   Log messages.
   */
  public function getLogMessages() : array {
    return $this->logMessages;
  }

  /**
   * {@inheritDoc}
   */
  public function setRequestStack(RequestStack $requestStack = NULL) {
  }

  /**
   * {@inheritDoc}
   */
  public function setCurrentUser(AccountInterface $current_user = NULL) {
  }

  /**
   * {@inheritDoc}
   */
  public function setLoggers(array $loggers) {
  }

  /**
   * {@inheritDoc}
   */
  public function addLogger(LoggerInterface $logger, $priority = 0) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoggerMock::$logMessages protected property Log messages.
LoggerMock::$parser protected property The message's placeholders parser.
LoggerMock::addLogger public function Adds a logger. Overrides LoggerChannelInterface::addLogger
LoggerMock::getLogMessages public function Helper method that can be used for assertions.
LoggerMock::log public function Logs with an arbitrary level. Overrides RfcLoggerTrait::log
LoggerMock::setCurrentUser public function Sets the current user. Overrides LoggerChannelInterface::setCurrentUser
LoggerMock::setLoggers public function Sets the loggers for this channel. Overrides LoggerChannelInterface::setLoggers
LoggerMock::setRequestStack public function Sets the request stack. Overrides LoggerChannelInterface::setRequestStack
LoggerMock::__construct public function Constructs a LoggerMock object.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function