From fc1e0d0aeef8d7d08ee2247aa086301c6bf05e0a Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Mon, 4 Nov 2024 11:51:29 +0300 Subject: [PATCH 1/3] Expand all objects with the infinite limit of discovering --- src/Dumper.php | 14 ++++-- tests/Unit/DumperTest.php | 97 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/Dumper.php b/src/Dumper.php index 59ab5d8d..10ad2def 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -71,10 +71,12 @@ private function buildObjectsCache(mixed $variable, int $depth, int $level = 0): return; } $this->objects[$objectDescription] = $variable; - if ($depth <= $level + 1) { - return; - } $variable = $this->getObjectProperties($variable); + + foreach ($variable as $value) { + $this->buildObjectsCache($value, $depth, 0); + } + return; } if (is_array($variable)) { $nextLevel = $level + 1; @@ -159,7 +161,11 @@ private function dumpNestedInternal( break; } - if ($objectCollapseLevel < $level && array_key_exists($objectDescription, $this->objects)) { + if (!array_key_exists($objectDescription, $this->objects)) { + $output = 'object@' . $objectDescription; + $this->objects[$objectDescription] = $variable; + break; + } elseif ($objectCollapseLevel < $level) { $output = 'object@' . $objectDescription; break; } diff --git a/tests/Unit/DumperTest.php b/tests/Unit/DumperTest.php index 8ffcb277..ebd16849 100644 --- a/tests/Unit/DumperTest.php +++ b/tests/Unit/DumperTest.php @@ -19,6 +19,103 @@ final class DumperTest extends TestCase { + public function testObjectExpanding(): void + { + $var = $this->createNested(10, [[[[[[[[['key' => 'end']]]]]]]]]); + + $lvl1Id = spl_object_id($var); + $lvl2Id = spl_object_id($var->prop1); + $lvl3Id = spl_object_id($var->prop1->prop1); + $lvl4Id = spl_object_id($var->prop1->prop1->prop1); + $lvl5Id = spl_object_id($var->prop1->prop1->prop1->prop1); + $lvl6Id = spl_object_id($var->prop1->prop2->prop1->prop1->prop1); + $lvl7Id = spl_object_id($var->prop1->prop2->prop1->prop1->prop1->prop1); + $lvl8Id = spl_object_id($var->prop1->prop2->prop1->prop1->prop1->prop1->prop1); + $lvl9Id = spl_object_id($var->prop1->prop2->prop1->prop1->prop1->prop1->prop1->prop1); + $lvl10Id = spl_object_id($var->prop1->prop2->prop1->prop1->prop1->prop1->prop1->prop1->prop1); + + $expectedResult = <<asJsonObjectsMap(4, true); + + $this->assertEquals($expectedResult, $actualResult); + } + + private function createNested(int $depth, mixed $data): object + { + $head = $lvl = new stdClass(); + $lvl->id = 'lvl1'; + + for ($i = 2; $i <= $depth; $i++) { + $nested = new stdClass(); + $nested->id = 'lvl'.$i; + $lvl->prop1 = $nested; + $lvl->prop2 = $nested; + $lvl = $nested; + } + $lvl->loop = $data; + $lvl->head = $head; + + return $head; + } + /** * @dataProvider asJsonObjectMapDataProvider */ From e145f456c87ca549bda851b6ae6625d9af46a7cb Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Nov 2024 08:51:47 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- src/Dumper.php | 3 ++- tests/Unit/DumperTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Dumper.php b/src/Dumper.php index 10ad2def..0fdaee87 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -165,7 +165,8 @@ private function dumpNestedInternal( $output = 'object@' . $objectDescription; $this->objects[$objectDescription] = $variable; break; - } elseif ($objectCollapseLevel < $level) { + } + if ($objectCollapseLevel < $level) { $output = 'object@' . $objectDescription; break; } diff --git a/tests/Unit/DumperTest.php b/tests/Unit/DumperTest.php index ebd16849..85c81f25 100644 --- a/tests/Unit/DumperTest.php +++ b/tests/Unit/DumperTest.php @@ -105,7 +105,7 @@ private function createNested(int $depth, mixed $data): object for ($i = 2; $i <= $depth; $i++) { $nested = new stdClass(); - $nested->id = 'lvl'.$i; + $nested->id = 'lvl' . $i; $lvl->prop1 = $nested; $lvl->prop2 = $nested; $lvl = $nested; From d3dca3d1961045ae5f75beecbb22bcecfa19c725 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Mon, 4 Nov 2024 12:03:06 +0300 Subject: [PATCH 3/3] FIx another test --- tests/Unit/Collector/ContainerInterfaceProxyTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Unit/Collector/ContainerInterfaceProxyTest.php b/tests/Unit/Collector/ContainerInterfaceProxyTest.php index c5b3a87c..a9a99799 100644 --- a/tests/Unit/Collector/ContainerInterfaceProxyTest.php +++ b/tests/Unit/Collector/ContainerInterfaceProxyTest.php @@ -158,9 +158,8 @@ public function testGetAndHasWithWrongId(): void $this->expectException(ContainerExceptionInterface::class); $this->expectExceptionMessage( sprintf( - 'No definition or class found or resolvable for "%s" while building "%s".', + 'No definition or class found or resolvable for "%s" while building it.', CollectorInterface::class, - CollectorInterface::class ) ); $containerProxy->get(CollectorInterface::class);