‪TYPO3CMS  11.5
IntrospectionProcessorTest.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\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪IntrospectionProcessorTest extends UnitTestCase
30 {
34  protected ‪$processor;
35 
39  protected array ‪$dummyBacktrace = [
40  [
41  'file' => '/foo/filename1.php',
42  'line' => 1,
43  'class' => 'class1',
44  'function' => 'function1',
45  ],
46  [
47  'file' => '/foo/filename2.php',
48  'line' => 2,
49  'class' => 'class2',
50  'function' => 'function2',
51  ],
52  [
53  'class' => 'class3',
54  'function' => 'function3',
55  ],
56  [
57  'file' => '/foo/filename4.php',
58  'line' => 4,
59  'class' => 'class4',
60  'function' => 'function4',
61  ],
62  ];
63 
67  protected function ‪setUp(): void
68  {
69  parent::setUp();
70  $this->processor = $this->getAccessibleMock(
71  IntrospectionProcessor::class,
72  ['getDebugBacktrace', 'formatDebugBacktrace']
73  );
74  }
75 
80  {
81  $this->processor->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
82  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
83  $logRecord = $this->processor->processLogRecord($logRecord);
84 
85  self::assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
86  self::assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
87  self::assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
88  self::assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
89  }
90 
95  {
97  array_unshift(
99  [
100  'file' => '/foo/Log.php',
101  'line' => 999,
102  'class' => 'TYPO3\CMS\Core\Log\Bar\Foo',
103  'function' => 'function999',
104  ],
105  [
106  'file' => '/foo/Log2.php',
107  'line' => 888,
108  'class' => 'TYPO3\CMS\Core\Log\Bar2\Foo2',
109  'function' => 'function888',
110  ]
111  );
112  $this->processor->method('getDebugBacktrace')->willReturn(‪$dummyBacktrace);
113 
114  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
115  $logRecord = $this->processor->processLogRecord($logRecord);
116 
117  self::assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
118  self::assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
119  self::assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
120  self::assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
121  }
122 
127  {
128  return [
129  ['0'],
130  ['1'],
131  ['3'],
132  ];
133  }
134 
140  {
141  $this->processor->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
142  $this->processor->setShiftBackTraceLevel($number);
143 
144  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
145  $logRecord = $this->processor->processLogRecord($logRecord);
146 
147  self::assertEquals($this->dummyBacktrace[$number]['file'], $logRecord['data']['file']);
148  self::assertEquals($this->dummyBacktrace[$number]['line'], $logRecord['data']['line']);
149  self::assertEquals($this->dummyBacktrace[$number]['class'], $logRecord['data']['class']);
150  self::assertEquals($this->dummyBacktrace[$number]['function'], $logRecord['data']['function']);
151  }
152 
157  {
158  $this->processor->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
159  $this->processor->setShiftBackTraceLevel(4);
160 
161  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
162  $logRecord = $this->processor->processLogRecord($logRecord);
163 
164  self::assertEquals($this->dummyBacktrace[3]['file'], $logRecord['data']['file']);
165  self::assertEquals($this->dummyBacktrace[3]['line'], $logRecord['data']['line']);
166  self::assertEquals($this->dummyBacktrace[3]['class'], $logRecord['data']['class']);
167  self::assertEquals($this->dummyBacktrace[3]['function'], $logRecord['data']['function']);
168  }
169 
174  {
175  $this->processor->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
176 
177  $this->processor->setAppendFullBackTrace(true);
178 
179  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
180  $logRecord = $this->processor->processLogRecord($logRecord);
181 
182  self::assertContains($this->dummyBacktrace[0], $logRecord['data']['backtrace']);
183  self::assertContains($this->dummyBacktrace[1], $logRecord['data']['backtrace']);
184  self::assertContains($this->dummyBacktrace[2], $logRecord['data']['backtrace']);
185  self::assertContains($this->dummyBacktrace[3], $logRecord['data']['backtrace']);
186  }
187 }
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\setUp
‪setUp()
Definition: IntrospectionProcessorTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider()
Definition: IntrospectionProcessorTest.php:125
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest
Definition: IntrospectionProcessorTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor
Definition: AbstractMemoryTest.php:18
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor
Definition: IntrospectionProcessor.php:24
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog
‪appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog()
Definition: IntrospectionProcessorTest.php:172
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels
‪introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels()
Definition: IntrospectionProcessorTest.php:155
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:22
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$processor
‪MockObject IntrospectionProcessor $processor
Definition: IntrospectionProcessorTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorAddsLastBacktraceItemToLogRecord
‪introspectionProcessorAddsLastBacktraceItemToLogRecord()
Definition: IntrospectionProcessorTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace($number)
Definition: IntrospectionProcessorTest.php:138
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$dummyBacktrace
‪array $dummyBacktrace
Definition: IntrospectionProcessorTest.php:38
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace
‪introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace()
Definition: IntrospectionProcessorTest.php:93