public function LogsHttpRegisterEventTest::testRegisterEvent in Logs HTTP 8
Test registration of an event.
File
- tests/
src/ Kernel/ LogsHttpRegisterEventTest.php, line 54
Class
- LogsHttpRegisterEventTest
- Test registration of an event.
Namespace
Drupal\Tests\logs_http\KernelCode
public function testRegisterEvent() {
// Test severity.
\Drupal::logger('logs_http')
->notice('Notice 1');
$events = $this->logsHttpLogger
->getEvents();
$this
->assertEmpty($events, 'No notice events registered, as severity level was too high.');
// Set severity.
$this->logsHttpConfig
->set('severity_level', RfcLogLevel::NOTICE);
$this->logsHttpConfig
->save();
// Test single event.
$this->logsHttpLogger
->reset();
\Drupal::logger('logs_http')
->error('Notice 1');
$events = $this->logsHttpLogger
->getEvents();
$this
->assertEquals(1, count($events), 'Notice events registered.');
// Test multiple events.
$this->logsHttpLogger
->reset();
// A duplicated event.
\Drupal::logger('logs_http')
->notice('Notice 1');
\Drupal::logger('logs_http')
->notice('Notice 1');
\Drupal::logger('logs_http')
->notice('Notice 2');
$events = $this->logsHttpLogger
->getEvents();
$this
->assertEquals(2, count($events), 'Correct number of events registered.');
// Get the elements.
$event1 = array_shift($events);
$event2 = array_shift($events);
$this
->assertEquals('Notice 1', $event1['message'], 'Correct first event registered.');
$this
->assertEquals('Notice 2', $event2['message'], 'Correct second event registered.');
}