‪TYPO3CMS  10.4
IntrospectionProcessorTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪IntrospectionProcessorTest extends UnitTestCase
27 {
31  protected ‪$processor;
32 
38  protected ‪$dummyBacktrace = [
39  [
40  'file' => '/foo/filename1.php',
41  'line' => 1,
42  'class' => 'class1',
43  'function' => 'function1'
44  ],
45  [
46  'file' => '/foo/filename2.php',
47  'line' => 2,
48  'class' => 'class2',
49  'function' => 'function2'
50  ],
51  [
52  'class' => 'class3',
53  'function' => 'function3'
54  ],
55  [
56  'file' => '/foo/filename4.php',
57  'line' => 4,
58  'class' => 'class4',
59  'function' => 'function4'
60  ]
61  ];
62 
66  protected function ‪setUp(): void
67  {
68  parent::setUp();
69  $this->processor = $this->getAccessibleMock(
70  IntrospectionProcessor::class,
71  ['getDebugBacktrace', 'formatDebugBacktrace']
72  );
73  }
74 
79  {
80  $this->processor->expects(self::any())->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
81  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
82  $logRecord = $this->processor->processLogRecord($logRecord);
83 
84  self::assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
85  self::assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
86  self::assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
87  self::assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
88  }
89 
94  {
96  array_unshift(
98  [
99  'file' => '/foo/Log.php',
100  'line' => 999,
101  'class' => 'TYPO3\CMS\Core\Log\Bar\Foo',
102  'function' => 'function999'
103  ],
104  [
105  'file' => '/foo/Log2.php',
106  'line' => 888,
107  'class' => 'TYPO3\CMS\Core\Log\Bar2\Foo2',
108  'function' => 'function888'
109  ]
110  );
111  $this->processor->expects(self::any())->method('getDebugBacktrace')->willReturn(‪$dummyBacktrace);
112 
113  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
114  $logRecord = $this->processor->processLogRecord($logRecord);
115 
116  self::assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
117  self::assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
118  self::assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
119  self::assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
120  }
121 
126  {
127  return [
128  ['0'],
129  ['1'],
130  ['3']
131  ];
132  }
133 
139  {
140  $this->processor->expects(self::any())->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
141  $this->processor->setShiftBackTraceLevel($number);
142 
143  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
144  $logRecord = $this->processor->processLogRecord($logRecord);
145 
146  self::assertEquals($this->dummyBacktrace[$number]['file'], $logRecord['data']['file']);
147  self::assertEquals($this->dummyBacktrace[$number]['line'], $logRecord['data']['line']);
148  self::assertEquals($this->dummyBacktrace[$number]['class'], $logRecord['data']['class']);
149  self::assertEquals($this->dummyBacktrace[$number]['function'], $logRecord['data']['function']);
150  }
151 
156  {
157  $this->processor->expects(self::any())->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
158  $this->processor->setShiftBackTraceLevel(4);
159 
160  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
161  $logRecord = $this->processor->processLogRecord($logRecord);
162 
163  self::assertEquals($this->dummyBacktrace[3]['file'], $logRecord['data']['file']);
164  self::assertEquals($this->dummyBacktrace[3]['line'], $logRecord['data']['line']);
165  self::assertEquals($this->dummyBacktrace[3]['class'], $logRecord['data']['class']);
166  self::assertEquals($this->dummyBacktrace[3]['function'], $logRecord['data']['function']);
167  }
168 
173  {
174  $this->processor->expects(self::any())->method('getDebugBacktrace')->willReturn($this->dummyBacktrace);
175 
176  $this->processor->setAppendFullBackTrace(true);
177 
178  $logRecord = new ‪LogRecord('test.core.log', LogLevel::DEBUG, 'test');
179  $logRecord = $this->processor->processLogRecord($logRecord);
180 
181  self::assertContains($this->dummyBacktrace[0], $logRecord['data']['backtrace']);
182  self::assertContains($this->dummyBacktrace[1], $logRecord['data']['backtrace']);
183  self::assertContains($this->dummyBacktrace[2], $logRecord['data']['backtrace']);
184  self::assertContains($this->dummyBacktrace[3], $logRecord['data']['backtrace']);
185  }
186 }
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\setUp
‪setUp()
Definition: IntrospectionProcessorTest.php:64
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider()
Definition: IntrospectionProcessorTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest
Definition: IntrospectionProcessorTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$processor
‪PHPUnit Framework MockObject MockObject TYPO3 CMS Core Log Processor IntrospectionProcessor $processor
Definition: IntrospectionProcessorTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor
Definition: AbstractMemoryTest.php:16
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor
Definition: IntrospectionProcessor.php:24
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog
‪appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog()
Definition: IntrospectionProcessorTest.php:170
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels
‪introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels()
Definition: IntrospectionProcessorTest.php:153
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:22
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorAddsLastBacktraceItemToLogRecord
‪introspectionProcessorAddsLastBacktraceItemToLogRecord()
Definition: IntrospectionProcessorTest.php:76
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace($number)
Definition: IntrospectionProcessorTest.php:136
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$dummyBacktrace
‪array $dummyBacktrace
Definition: IntrospectionProcessorTest.php:36
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace
‪introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace()
Definition: IntrospectionProcessorTest.php:91