[BUGFIX] Unit tests call parent::tearDown()
[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\Extbase\Utility\DebuggerUtility;
17
18 /**
19 * Test case
20 */
21 class DebuggerUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
23 /**
24 * @test
25 */
26 public function debuggerRewindsInstancesOfIterator()
27 {
28 /** @var $objectStorage \TYPO3\CMS\Extbase\Persistence\ObjectStorage */
29 $objectStorage = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class)
30 ->setMethods(['dummy'])
31 ->getMock();
32 for ($i = 0; $i < 5; $i++) {
33 $obj = new \stdClass();
34 $obj->property = $i;
35 $objectStorage->attach($obj);
36 }
37 DebuggerUtility::var_dump($objectStorage, null, 8, true, false, true);
38 $this->assertTrue($objectStorage->valid());
39 }
40
41 /**
42 * @test
43 */
44 public function varDumpShowsPropertiesOfStdClassObjects()
45 {
46 $testObject = new \stdClass();
47 $testObject->foo = 'bar';
48 $result = DebuggerUtility::var_dump($testObject, null, 8, true, false, true);
49 $this->assertRegExp('/foo.*bar/', $result);
50 }
51
52 /**
53 * @test
54 */
55 public function varDumpHandlesVariadicArguments()
56 {
57 $result = DebuggerUtility::var_dump(function (...$args) {
58 }, null, 8, true, false, true);
59 $this->assertContains('function (...$args)', $result);
60 }
61
62 /**
63 * @test
64 */
65 public function varDumpRespectsBlacklistedProperties()
66 {
67 $testClass = new \stdClass();
68 $testClass->secretData = 'I like cucumber.';
69 $testClass->notSoSecretData = 'I like burger.';
70
71 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, null, ['secretData']);
72 self::assertNotContains($testClass->secretData, $result);
73 }
74
75 /**
76 * @test
77 */
78 public function varDumpRespectsBlacklistedClasses()
79 {
80 $testClass = new \stdClass();
81 $testClass->data = 'I like burger.';
82
83 $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, [\stdClass::class]);
84 self::assertNotContains($testClass->data, $result);
85 }
86 }