‪TYPO3CMS  ‪main
DatabaseWriterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪DatabaseWriterTest extends FunctionalTestCase
28 {
29  #[Test]
31  {
32  $logRecordData = [
33  'request_id' => '5862c0e7838ac',
34  'time_micro' => 1469740000.0,
35  'component' => 'aComponent',
36  'level' => ‪LogLevel::normalizeLevel(\Psr\Log\LogLevel::DEBUG),
37  'message' => 'aMessage',
38  'data' => '',
39  ];
40  $logRecord = new ‪LogRecord(
41  $logRecordData['component'],
42  \Psr\Log\LogLevel::DEBUG,
43  $logRecordData['message'],
44  [],
45  $logRecordData['request_id']
46  );
47  $logRecord->setCreated($logRecordData['time_micro']);
48 
49  (new ‪DatabaseWriter())->writeLog($logRecord);
50 
51  $rowInDatabase = (new ‪ConnectionPool())->getConnectionForTable('sys_log')
52  ->select(
53  array_keys($logRecordData),
54  'sys_log',
55  ['request_id' => $logRecordData['request_id']]
56  )
57  ->fetchAssociative();
58 
59  self::assertEquals($logRecordData, $rowInDatabase);
60  }
61 }
‪TYPO3\CMS\Core\Tests\Functional\Log\Writer\DatabaseWriterTest\writeLogInsertsLogRecordWithGivenProperties
‪writeLogInsertsLogRecordWithGivenProperties()
Definition: DatabaseWriterTest.php:30
‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter
Definition: DatabaseWriter.php:27
‪TYPO3\CMS\Core\Log\LogLevel\normalizeLevel
‪static normalizeLevel($level)
Definition: LogLevel.php:90
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:24
‪TYPO3\CMS\Core\Tests\Functional\Log\Writer\DatabaseWriterTest
Definition: DatabaseWriterTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Log\Writer
Definition: DatabaseWriterTest.php:18
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24