TYPO3 CMS  TYPO3_8-7
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 
20 class IntrospectionProcessorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $processor;
26 
32  protected $dummyBacktrace = [
33  [
34  'file' => '/foo/filename1.php',
35  'line' => 1,
36  'class' => 'class1',
37  'function' => 'function1'
38  ],
39  [
40  'file' => '/foo/filename2.php',
41  'line' => 2,
42  'class' => 'class2',
43  'function' => 'function2'
44  ],
45  [
46  'class' => 'class3',
47  'function' => 'function3'
48  ],
49  [
50  'file' => '/foo/filename4.php',
51  'line' => 4,
52  'class' => 'class4',
53  'function' => 'function4'
54  ]
55  ];
56 
60  protected function setUp()
61  {
62  $this->processor = $this->getAccessibleMock(
63  \TYPO3\CMS\Core\Log\Processor\IntrospectionProcessor::class,
64  ['getDebugBacktrace', 'formatDebugBacktrace']
65  );
66  }
67 
72  {
73  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
74  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \TYPO3\CMS\Core\Log\LogLevel::DEBUG, 'test');
75  $logRecord = $this->processor->processLogRecord($logRecord);
76 
77  $this->assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
78  $this->assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
79  $this->assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
80  $this->assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
81  }
82 
87  {
89  array_unshift(
91  [
92  'file' => '/foo/Log.php',
93  'line' => 999,
94  'class' => 'TYPO3\CMS\Core\Log\Bar\Foo',
95  'function' => 'function999'
96  ],
97  [
98  'file' => '/foo/Log2.php',
99  'line' => 888,
100  'class' => 'TYPO3\CMS\Core\Log\Bar2\Foo2',
101  'function' => 'function888'
102  ]
103  );
104  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($dummyBacktrace));
105 
106  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \TYPO3\CMS\Core\Log\LogLevel::DEBUG, 'test');
107  $logRecord = $this->processor->processLogRecord($logRecord);
108 
109  $this->assertEquals($this->dummyBacktrace[0]['file'], $logRecord['data']['file']);
110  $this->assertEquals($this->dummyBacktrace[0]['line'], $logRecord['data']['line']);
111  $this->assertEquals($this->dummyBacktrace[0]['class'], $logRecord['data']['class']);
112  $this->assertEquals($this->dummyBacktrace[0]['function'], $logRecord['data']['function']);
113  }
114 
119  {
120  return [
121  ['0'],
122  ['1'],
123  ['3']
124  ];
125  }
126 
132  {
133  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
134  $this->processor->setShiftBackTraceLevel($number);
135 
136  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \TYPO3\CMS\Core\Log\LogLevel::DEBUG, 'test');
137  $logRecord = $this->processor->processLogRecord($logRecord);
138 
139  $this->assertEquals($this->dummyBacktrace[$number]['file'], $logRecord['data']['file']);
140  $this->assertEquals($this->dummyBacktrace[$number]['line'], $logRecord['data']['line']);
141  $this->assertEquals($this->dummyBacktrace[$number]['class'], $logRecord['data']['class']);
142  $this->assertEquals($this->dummyBacktrace[$number]['function'], $logRecord['data']['function']);
143  }
144 
149  {
150  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
151  $this->processor->setShiftBackTraceLevel(4);
152 
153  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \TYPO3\CMS\Core\Log\LogLevel::DEBUG, 'test');
154  $logRecord = $this->processor->processLogRecord($logRecord);
155 
156  $this->assertEquals($this->dummyBacktrace[3]['file'], $logRecord['data']['file']);
157  $this->assertEquals($this->dummyBacktrace[3]['line'], $logRecord['data']['line']);
158  $this->assertEquals($this->dummyBacktrace[3]['class'], $logRecord['data']['class']);
159  $this->assertEquals($this->dummyBacktrace[3]['function'], $logRecord['data']['function']);
160  }
161 
166  {
167  $this->processor->expects($this->any())->method('getDebugBacktrace')->will($this->returnValue($this->dummyBacktrace));
168 
169  $this->processor->setAppendFullBackTrace(true);
170 
171  $logRecord = new \TYPO3\CMS\Core\Log\LogRecord('test.core.log', \TYPO3\CMS\Core\Log\LogLevel::DEBUG, 'test');
172  $logRecord = $this->processor->processLogRecord($logRecord);
173 
174  $this->assertContains($this->dummyBacktrace[0], $logRecord['data']['backtrace']);
175  $this->assertContains($this->dummyBacktrace[1], $logRecord['data']['backtrace']);
176  $this->assertContains($this->dummyBacktrace[2], $logRecord['data']['backtrace']);
177  $this->assertContains($this->dummyBacktrace[3], $logRecord['data']['backtrace']);
178  }
179 }