Browse Source

add __debugInfo to ResultSetDecorator

Kevin Pfeifer 2 years ago
parent
commit
9db3d5d719

+ 10 - 0
src/Datasource/ResultSetDecorator.php

@@ -46,4 +46,14 @@ class ResultSetDecorator extends Collection implements ResultSetInterface
 
         return count($this->toArray());
     }
+
+    /**
+     * @inheritDoc
+     */
+    public function __debugInfo(): array
+    {
+        $parentInfo = parent::__debugInfo();
+
+        return array_merge($parentInfo, ['items' => $this->toArray()]);
+    }
 }

+ 13 - 0
tests/TestCase/Datasource/ResultSetDecoratorTest.php

@@ -89,4 +89,17 @@ class ResultSetDecoratorTest extends TestCase
         $this->assertSame(3, $decorator->count());
         $this->assertCount(3, $decorator);
     }
+
+    /**
+     * Test the __debugInfo() method which is used by DebugKit
+     */
+    public function testDebugInfo(): void
+    {
+        $data = new ArrayIterator([1, 2, 3]);
+        $decorator = new ResultSetDecorator($data);
+        $this->assertEquals([
+            'count' => 3,
+            'items' => [1, 2, 3],
+        ], $decorator->__debugInfo());
+    }
 }