function RulesDebugLoggerChannelTest::testLog
Tests LoggerChannel::log().
@dataProvider providerTestLog
@covers ::log
Parameters
string $psr3_message_level: Expected PSR3 log level.
int $rfc_message_level: Expected RFC 5424 log level.
bool $system_debug: Is system debug logging enabled.
bool $debug_log_enabled: Is debug logging enabled.
string $psr3_log_error_level: Minimum required PSR3 log level at which to log.
int $expect_system_log: Number of logs expected to be created.
int $expect_screen_log: Number of messages expected to be created.
string $message: Log message.
File
-
tests/
src/ Unit/ RulesDebugLoggerChannelTest.php, line 92
Class
- RulesDebugLoggerChannelTest
- @coversDefaultClass \Drupal\rules\Logger\RulesDebugLoggerChannel @group Rules
Namespace
Drupal\Tests\rules\UnitCode
public function testLog($psr3_message_level, $rfc_message_level, $system_debug, $debug_log_enabled, $psr3_log_error_level, $expect_system_log, $expect_screen_log, $message) {
// Clean up after previous test.
$this->rulesDebugLog
->clearLogs();
$config = $this->getConfigFactoryStub([
'rules.settings' => [
'system_log' => [
'log_level' => $psr3_log_error_level,
],
'debug_log' => [
'enabled' => $debug_log_enabled,
'system_debug' => $system_debug,
'log_level' => $psr3_log_error_level,
],
],
]);
$channel = new RulesDebugLoggerChannel($this->rulesDebugLog, $config);
$addedLogger = $this->prophesize(LoggerInterface::class);
$addedLogger->log($rfc_message_level, $message, Argument::type('array'))
->shouldBeCalledTimes($expect_screen_log);
$channel->addLogger($addedLogger->reveal());
$channel->log($psr3_message_level, $message, []);
$messages = $this->rulesDebugLog
->getLogs();
if ($expect_screen_log > 0) {
$this->assertNotNull($messages);
$context = [
'channel' => 'rules_debug',
'link' => '',
'element' => NULL,
'scope' => NULL,
'path' => NULL,
];
$context += $messages[0]['context'];
$this->assertEquals([
0 => [
'message' => $message,
'context' => $context,
'level' => $psr3_message_level,
'timestamp' => $context['timestamp'],
'scope' => NULL,
'path' => NULL,
],
], $messages, "actual =" . var_export($messages, TRUE));
}
else {
$this->assertCount(0, $messages);
}
}