[TASK] Make LogManagerTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Log / LogManagerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Log;
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
18 use TYPO3\CMS\Core\Log\Logger;
19 use TYPO3\CMS\Core\Log\LogLevel;
20 use TYPO3\CMS\Core\Log\LogManager;
21 use TYPO3\CMS\Core\Log\Processor\NullProcessor;
22 use TYPO3\CMS\Core\Log\Writer\NullWriter;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class LogManagerTest extends UnitTestCase
30 {
31 /**
32 * @var \TYPO3\CMS\Core\Log\LogManager
33 */
34 protected $logManagerInstance = null;
35
36 protected function setUp()
37 {
38 $this->logManagerInstance = GeneralUtility::makeInstance(LogManager::class);
39 }
40
41 protected function tearDown()
42 {
43 GeneralUtility::makeInstance(LogManager::class)->reset();
44 parent::tearDown();
45 }
46
47 /**
48 * @test
49 */
50 public function logManagerReturnsLoggerWhenRequestedWithGetLogger()
51 {
52 $this->assertInstanceOf(Logger::class, $this->logManagerInstance->getLogger('test'));
53 }
54
55 /**
56 * @test
57 */
58 public function logManagerTurnsUnderScoreStyleLoggerNamesIntoDotStyleLoggerNames()
59 {
60 $this->assertSame('test.a.b', $this->logManagerInstance->getLogger('test_a_b')->getName());
61 }
62
63 /**
64 * @test
65 */
66 public function logManagerTurnsNamespaceStyleLoggerNamesIntoDotStyleLoggerNames()
67 {
68 $this->assertSame('test.a.b', $this->logManagerInstance->getLogger('test\\a\\b')->getName());
69 }
70
71 /**
72 * @test
73 */
74 public function managerReturnsSameLoggerOnRepeatedRequest()
75 {
76 $loggerName = $this->getUniqueId('test.core.log');
77 $this->logManagerInstance->registerLogger($loggerName);
78 $logger1 = $this->logManagerInstance->getLogger($loggerName);
79 $logger2 = $this->logManagerInstance->getLogger($loggerName);
80 $this->assertSame($logger1, $logger2);
81 }
82
83 /**
84 * @test
85 */
86 public function configuresLoggerWithConfiguredWriter()
87 {
88 $component = 'test';
89 $writer = NullWriter::class;
90 $level = LogLevel::DEBUG;
91 $GLOBALS['TYPO3_CONF_VARS']['LOG'][$component]['writerConfiguration'] = [
92 $level => [
93 $writer => []
94 ]
95 ];
96 /** @var $logger \TYPO3\CMS\Core\Log\Logger */
97 $logger = $this->logManagerInstance->getLogger($component);
98 $writers = $logger->getWriters();
99 $this->assertInstanceOf($writer, $writers[$level][0]);
100 }
101
102 /**
103 * @test
104 */
105 public function configuresLoggerWithConfiguredProcessor()
106 {
107 $component = 'test';
108 $processor = NullProcessor::class;
109 $level = LogLevel::DEBUG;
110 $GLOBALS['TYPO3_CONF_VARS']['LOG'][$component]['processorConfiguration'] = [
111 $level => [
112 $processor => []
113 ]
114 ];
115 /** @var $logger \TYPO3\CMS\Core\Log\Logger */
116 $logger = $this->logManagerInstance->getLogger($component);
117 $processors = $logger->getProcessors();
118 $this->assertInstanceOf($processor, $processors[$level][0]);
119 }
120 }