[TASK] Doctrine: Migrate DatabaseWriter
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Log / Writer / DatabaseWriterTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Log\Writer;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Bootstrap;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Log\LogLevel;
20 use TYPO3\CMS\Core\Log\LogRecord;
21 use TYPO3\CMS\Core\Log\Writer\DatabaseWriter;
22 use TYPO3\CMS\Core\Tests\FunctionalTestCase;
23
24 /**
25 * Test case
26 */
27 class DatabaseWriterTest extends FunctionalTestCase
28 {
29 /**
30 * @test
31 */
32 public function writeLogInsertsLogRecordWithGivenProperties()
33 {
34 $logRecordData = array(
35 'request_id' => Bootstrap::getInstance()->getRequestId(),
36 'time_micro' => 1469740000.0,
37 'component' => 'aComponent',
38 'level' => LogLevel::DEBUG,
39 'message' => 'aMessage',
40 'data' => '',
41 );
42 $logRecord = new LogRecord(
43 $logRecordData['component'],
44 $logRecordData['level'],
45 $logRecordData['message'],
46 []
47 );
48 $logRecord->setCreated($logRecordData['time_micro']);
49
50 (new DatabaseWriter())->writeLog($logRecord);
51
52 $rowInDatabase = (new ConnectionPool())->getConnectionForTable('sys_log')
53 ->select(
54 array_keys($logRecordData),
55 'sys_log',
56 ['request_id' => $logRecordData['request_id']]
57 )
58 ->fetch();
59
60 $this->assertEquals($logRecordData, $rowInDatabase);
61 }
62 }