diff --git a/src/Helper/PartialLoop.php b/src/Helper/PartialLoop.php index 7ea3b315..1b583790 100644 --- a/src/Helper/PartialLoop.php +++ b/src/Helper/PartialLoop.php @@ -46,7 +46,7 @@ public function __invoke($name = null, $values = null) if (!is_array($values)) { if ($values instanceof Traversable) { - $values = ArrayUtils::iteratorToArray($values); + $values = ArrayUtils::iteratorToArray($values, false); } elseif (is_object($values) && method_exists($values, 'toArray')) { $values = $values->toArray(); } else { diff --git a/test/Helper/PartialLoopTest.php b/test/Helper/PartialLoopTest.php index e70eff07..68ecfdd0 100644 --- a/test/Helper/PartialLoopTest.php +++ b/test/Helper/PartialLoopTest.php @@ -297,6 +297,30 @@ public function testPartialLoopPartialCounterResets() $this->helper->__invoke('partialLoopCouter.phtml', $data); $this->assertEquals(4, $this->helper->getPartialCounter()); } + + public function testShouldNotConvertToArrayRecursivelyIfModelIsTraversable() + { + $rIterator = new RecursiveIteratorTest(); + for ($i = 0; $i < 5; ++$i) { + $data = array( + 'message' => 'foo' . $i, + ); + $rIterator->addItem(new IteratorTest($data)); + } + + $view = new View(); + $view->resolver()->addPath($this->basePath . '/application/views/scripts'); + $this->helper->setView($view); + $this->helper->setObjectKey('obj'); + + $result = $this->helper->__invoke('partialLoopShouldNotConvertToArrayRecursively.phtml', $rIterator); + + foreach ($rIterator as $item) { + foreach ($item as $key => $value) { + $this->assertContains('This is an iteration: ' . $value, $result, var_export($value, 1)); + } + } + } } class IteratorTest implements Iterator diff --git a/test/Helper/_files/modules/application/views/scripts/partialLoopShouldNotConvertToArrayRecursively.phtml b/test/Helper/_files/modules/application/views/scripts/partialLoopShouldNotConvertToArrayRecursively.phtml new file mode 100644 index 00000000..d0ed0395 --- /dev/null +++ b/test/Helper/_files/modules/application/views/scripts/partialLoopShouldNotConvertToArrayRecursively.phtml @@ -0,0 +1,5 @@ +obj)): ?> +No object model passed +obj->current() . "\n"; +endif;