public function JsonLogTest::testCanPrepareLogFile in JSONlog 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/JsonLogTest.php \Drupal\Tests\jsonlog\Unit\JsonLogTest::testCanPrepareLogFile()
- 3.x tests/src/Unit/JsonLogTest.php \Drupal\Tests\jsonlog\Unit\JsonLogTest::testCanPrepareLogFile()
test to see if a log file is well prepared
File
- tests/
src/ Unit/ JsonLogTest.php, line 69
Class
- JsonLogTest
- Unit tests for JsonLog class
Namespace
Drupal\Tests\jsonlog\UnitCode
public function testCanPrepareLogFile() {
$request_mock = $this
->createMock('Symfony\\Component\\HttpFoundation\\Request');
$request_mock
->expects($this
->exactly(1))
->method('getRealMethod')
->willReturn('POST');
/** @var Request $request_mock */
$this
->setupContainerCurrentRequest($request_mock);
$test_context = [
'user' => NULL,
'ip' => '127.0.0.9',
'request_uri' => 'admin/help',
'channel' => '500',
'link' => '',
'referer' => '',
];
$level = self::DEFAULT_THRESHOLD - 1;
$log_entry = $this->jsonLogger
->prepareLog($level, 'test', $test_context);
$this
->assertFalse($log_entry === FALSE, 'Log entry constructed');
$this
->assertEquals(JsonLogData::class, get_class($log_entry));
$this
->assertEquals('500', $log_entry
->getData()['subtype'], 'Correct subtype logged');
$this
->assertEquals('127.0.0.9', $log_entry
->getData()['client_ip'], 'Correct client_ip logged');
$this
->assertEquals('admin/help', $log_entry
->getData()['request_uri'], 'Correct request_uri logged');
$this
->assertEquals('POST', $log_entry
->getData()['method'], 'Correct method logged');
}