Skip to content

Commit

Permalink
[BUGFIX] Support DateTimeInterface in DebuggerUtility
Browse files Browse the repository at this point in the history
Change-Id: Ib38107456acd0f0535dc51083006ee77c5a81c17
Resolves: #87002
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/58949
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
andreaswolf authored and georgringer committed Dec 3, 2018
1 parent ba4ac56 commit af1642a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions typo3/sysext/extbase/Classes/Utility/DebuggerUtility.php
Expand Up @@ -297,13 +297,13 @@ protected static function renderHeader($object, $level, $plainText, $ansiColors)
}
} elseif (self::$renderedObjects->contains($object) && !$plainText) {
$dump = '<a href="javascript:;" onclick="document.location.hash=\'#' . spl_object_hash($object) . '\';" class="extbase-debug-seeabove">' . $dump . '<span class="extbase-debug-filtered">see above</span></a>';
} elseif ($level >= self::$maxDepth && !$object instanceof \DateTime) {
} elseif ($level >= self::$maxDepth && !$object instanceof \DateTimeInterface) {
if ($plainText) {
$dump .= ' ' . self::ansiEscapeWrap('max depth', '47;30', $ansiColors);
} else {
$dump .= '<span class="extbase-debug-filtered">max depth</span>';
}
} elseif ($level > 1 && !$object instanceof \DateTime && !$plainText) {
} elseif ($level > 1 && !$object instanceof \DateTimeInterface && !$plainText) {
if (($object instanceof \Countable && empty($object)) || empty($classReflection->getProperties())) {
$dump = '<span>' . $dump . '</span>';
} else {
Expand All @@ -314,8 +314,8 @@ protected static function renderHeader($object, $level, $plainText, $ansiColors)
$objectCount = count($object);
$dump .= $objectCount > 0 ? ' (' . $objectCount . ' items)' : ' (empty)';
}
if ($object instanceof \DateTime) {
$dump .= ' (' . $object->format(\DateTime::RFC3339) . ', ' . $object->getTimestamp() . ')';
if ($object instanceof \DateTimeInterface) {
$dump .= ' (' . $object->format(\DateTimeInterface::RFC3339) . ', ' . $object->getTimestamp() . ')';
}
if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface && !$object->_isNew()) {
$dump .= ' (uid=' . $object->getUid() . ', pid=' . $object->getPid() . ')';
Expand Down
22 changes: 22 additions & 0 deletions typo3/sysext/extbase/Tests/Unit/Utility/DebuggerUtilityTest.php
Expand Up @@ -84,4 +84,26 @@ public function varDumpRespectsBlacklistedClasses()
$result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, [\stdClass::class]);
self::assertNotContains($testClass->data, $result);
}

/**
* @test
*/
public function varDumpShowsDumpOfDateTime()
{
$date = \DateTime::createFromFormat('Y-m-d H:i:s', '2018-11-26 09:27:28', new \DateTimeZone('UTC'));

$result = DebuggerUtility::var_dump($date, null, 8, true, false, true, [\stdClass::class]);
self::assertContains('2018-11-26T09:27:28', $result);
}

/**
* @test
*/
public function varDumpShowsDumpOfDateTimeImmutable()
{
$date = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2018-11-26 09:27:28', new \DateTimeZone('UTC'));

$result = DebuggerUtility::var_dump($date, null, 8, true, false, true, [\stdClass::class]);
self::assertContains('2018-11-26T09:27:28', $result);
}
}

0 comments on commit af1642a

Please sign in to comment.