public function LoggerTest::testWatchdogLimit in MongoDB 8.2
Test the default and non-default mongodb_watchdog insertion behaviours.
Make sure the module applies the watchdog_limit variable,
@covers ::log
File
- modules/
mongodb_watchdog/ tests/ src/ Kernel/ LoggerTest.php, line 143
Class
- LoggerTest
- Class LoggerTest tests the logging mechanism itself.
Namespace
Drupal\Tests\mongodb_watchdog\KernelCode
public function testWatchdogLimit() {
$config = $this
->config(Logger::CONFIG_NAME);
$limit = $config
->get(Logger::CONFIG_LIMIT);
$this
->assertEquals(RfcLogLevel::DEBUG, $limit, (string) $this
->t('%name defaults to @level', [
'%name' => Logger::CONFIG_LIMIT,
'@level' => RfcLogLevel::DEBUG,
]));
$logger = $this->container
->get(Logger::SERVICE_LOGGER);
$database = $this->container
->get(MongoDb::SERVICE_DB_FACTORY)
->get(Logger::DB_LOGGER);
$this->collection = $database
->selectCollection(Logger::TEMPLATE_COLLECTION);
$this->collection
->drop();
$message = static::debrace($this
->randomString(32));
$logger
->log($limit, $message);
$this
->assertEntry($message);
// Now request a higher level: unimportant events should be ignored. For
// this to work, ensure limit is not the maximum level already.
$logger
->setLimit(RfcLogLevel::INFO);
$this->collection
->drop();
$message = $this
->randomMachineName(32);
$logger
->debug($message);
$this
->assertNoEntry($message);
// ... but events at the limit or more important should be logged.
$message = $this
->randomMachineName(32);
$logger
->notice($message);
$this
->assertEntry($message);
$message = $this
->randomMachineName(32);
$logger
->error($message);
$this
->assertEntry($message);
}