0ab272476b5c4581a4b3362963accd00e349ef90
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Utility / DebuggerUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
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 use TYPO3\CMS\Core\Tests\UnitTestCase;
17 use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
18
19 /**
20 * Test case
21 */
22 class DebuggerUtilityTest extends UnitTestCase
23 {
24 /**
25 * @var \TYPO3\CMS\Extbase\Utility\DebuggerUtility
26 */
27 protected $debugger;
28
29 protected function setUp()
30 {
31 $this->debugger = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Utility\DebuggerUtility::class, ['dummy']);
32 }
33
34 /**
35 * @test
36 */
37 public function debuggerRewindsInstancesOfIterator()
38 {
39 /** @var $objectStorage \TYPO3\CMS\Extbase\Persistence\ObjectStorage */
40 $objectStorage = $this->getMock(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class, ['dummy']);
41 for ($i = 0; $i < 5; $i++) {
42 $obj = new \StdClass();
43 $obj->property = $i;
44 $objectStorage->attach($obj);
45 }
46 $this->debugger->var_dump($objectStorage, null, 8, true, false, true);
47 $this->assertTrue($objectStorage->valid());
48 }
49
50 /**
51 * @test
52 */
53 public function debuggerDoesNotRewindInstanceOfArrayAccess()
54 {
55 $parameters = [];
56 for ($i = 0; $i < 5; $i++) {
57 $argument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('argument_' . $i, 'integer');
58 $parameters[$i] = $argument;
59 }
60
61 /** @var $arguments \TYPO3\CMS\Fluid\Core\ViewHelper\Arguments */
62 $arguments = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\Arguments::class, ['dummy'], ['arguments' => $parameters]);
63
64 $arguments->expects($this->never())->method('rewind');
65 $this->debugger->var_dump($arguments, null, 8, true, false, true);
66 }
67
68 /**
69 * @test
70 */
71 public function varDumpShowsPropertiesOfStdClassObjects()
72 {
73 $testObject = new \stdClass();
74 $testObject->foo = 'bar';
75 $result = $this->debugger->var_dump($testObject, null, 8, true, false, true);
76 $this->assertRegExp('/foo.*bar/', $result);
77 }
78
79 /**
80 * @test
81 * @return void
82 */
83 public function varDumpRespectsBlacklistedProperties()
84 {
85 $testClass = new \stdClass();
86 $testClass->secretData = 'I like cucumber.';
87 $testClass->notSoSecretData = 'I like burger.';
88
89 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, null, ['secretData']);
90 self::assertNotContains($testClass->secretData, $result);
91 }
92
93 /**
94 * @test
95 * @return void
96 */
97 public function varDumpRespectsBlacklistedClasses()
98 {
99 $testClass = new \stdClass();
100 $testClass->data = 'I like burger.';
101
102 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, [\stdClass::class]);
103 self::assertNotContains($testClass->data, $result);
104 }
105 }