‪TYPO3CMS  9.5
IntrospectionProcessorTest.php
Go to the documentation of this file.
1 <?php
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\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪IntrospectionProcessorTest extends UnitTestCase
23 {
27  protected ‪$processor;
28 
34  protected ‪$dummyBacktrace = [
35  [
36  'file' => '/foo/filename1.php',
37  'line' => 1,
38  'class' => 'class1',
39  'function' => 'function1'
40  ],
41  [
42  'file' => '/foo/filename2.php',
43  'line' => 2,
44  'class' => 'class2',
45  'function' => 'function2'
46  ],
47  [
48  'class' => 'class3',
49  'function' => 'function3'
50  ],
51  [
52  'file' => '/foo/filename4.php',
53  'line' => 4,
54  'class' => 'class4',
55  'function' => 'function4'
56  ]
57  ];
58 
62  protected function ‪setUp()
63  {
64  $this->processor = $this->getAccessibleMock(
65  \‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor::class,
66  ['getDebugBacktrace', 'formatDebugBacktrace']
67  );
68  }
69 
74  {
75  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
76  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \‪TYPO3\CMS\Core\Log\‪LogLevel::DEBUG, 'test');
77  $logRecord = $this->processor->processLogRecord($logRecord);
78 
79  $this->assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
80  $this->assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
81  $this->assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
82  $this->assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
83  }
84 
89  {
91  array_unshift(
93  [
94  'file' => '/foo/Log.php',
95  'line' => 999,
96  'class' => 'TYPO3\CMS\Core\Log\Bar\Foo',
97  'function' => 'function999'
98  ],
99  [
100  'file' => '/foo/Log2.php',
101  'line' => 888,
102  'class' => 'TYPO3\CMS\Core\Log\Bar2\Foo2',
103  'function' => 'function888'
104  ]
105  );
106  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue(‪$dummyBacktrace));
107 
108  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \‪TYPO3\CMS\Core\Log\‪LogLevel::DEBUG, 'test');
109  $logRecord = $this->processor->processLogRecord($logRecord);
110 
111  $this->assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
112  $this->assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
113  $this->assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
114  $this->assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
115  }
116 
121  {
122  return [
123  ['0'],
124  ['1'],
125  ['3']
126  ];
127  }
128 
134  {
135  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
136  $this->processor->setShiftBackTraceLevel($number);
137 
138  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \‪TYPO3\CMS\Core\Log\‪LogLevel::DEBUG, 'test');
139  $logRecord = $this->processor->processLogRecord($logRecord);
140 
141  $this->assertEquals($this->dummyBacktrace[$number]['file'], $logRecord['data']['file']);
142  $this->assertEquals($this->dummyBacktrace[$number]['line'], $logRecord['data']['line']);
143  $this->assertEquals($this->dummyBacktrace[$number]['class'], $logRecord['data']['class']);
144  $this->assertEquals($this->dummyBacktrace[$number]['function'], $logRecord['data']['function']);
145  }
146 
151  {
152  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
153  $this->processor->setShiftBackTraceLevel(4);
154 
155  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \‪TYPO3\CMS\Core\Log\‪LogLevel::DEBUG, 'test');
156  $logRecord = $this->processor->processLogRecord($logRecord);
157 
158  $this->assertEquals($this->dummyBacktrace[3]['file'], $logRecord['data']['file']);
159  $this->assertEquals($this->dummyBacktrace[3]['line'], $logRecord['data']['line']);
160  $this->assertEquals($this->dummyBacktrace[3]['class'], $logRecord['data']['class']);
161  $this->assertEquals($this->dummyBacktrace[3]['function'], $logRecord['data']['function']);
162  }
163 
168  {
169  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
170 
171  $this->processor->setAppendFullBackTrace(true);
172 
173  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \‪TYPO3\CMS\Core\Log\‪LogLevel::DEBUG, 'test');
174  $logRecord = $this->processor->processLogRecord($logRecord);
175 
176  $this->assertContains($this->dummyBacktrace[0], $logRecord['data']['backtrace']);
177  $this->assertContains($this->dummyBacktrace[1], $logRecord['data']['backtrace']);
178  $this->assertContains($this->dummyBacktrace[2], $logRecord['data']['backtrace']);
179  $this->assertContains($this->dummyBacktrace[3], $logRecord['data']['backtrace']);
180  }
181 }
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\setUp
‪setUp()
Definition: IntrospectionProcessorTest.php:60
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktraceDataProvider()
Definition: IntrospectionProcessorTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest
Definition: IntrospectionProcessorTest.php:23
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor
Definition: AbstractMemoryTest.php:2
‪TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor
Definition: IntrospectionProcessor.php:23
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog
‪appendFullBacktraceAddsTheFullBacktraceAsStringToTheLog()
Definition: IntrospectionProcessorTest.php:165
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels
‪introspectionProcessorLeavesOneEntryIfGivenNumberOfEntriesFromBacktraceIsGreaterOrEqualNumberOfBacktraceLevels()
Definition: IntrospectionProcessorTest.php:148
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$processor
‪PHPUnit_Framework_MockObject_MockObject TYPO3 CMS Core Log Processor IntrospectionProcessor $processor
Definition: IntrospectionProcessorTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorAddsLastBacktraceItemToLogRecord
‪introspectionProcessorAddsLastBacktraceItemToLogRecord()
Definition: IntrospectionProcessorTest.php:71
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace
‪introspectionProcessorShiftsGivenNumberOfEntriesFromBacktrace($number)
Definition: IntrospectionProcessorTest.php:131
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\$dummyBacktrace
‪array $dummyBacktrace
Definition: IntrospectionProcessorTest.php:32
‪TYPO3\CMS\Core\Log\LogLevel\DEBUG
‪const DEBUG
Definition: LogLevel.php:94
‪TYPO3\CMS\Core\Tests\Unit\Log\Processor\IntrospectionProcessorTest\introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace
‪introspectionProcessorShiftsLogRelatedFunctionsFromBacktrace()
Definition: IntrospectionProcessorTest.php:86