diff --git a/library/Zend/View/Helper/PartialLoop.php b/library/Zend/View/Helper/PartialLoop.php index 7b9f9f8201a..7ea3b315ad5 100644 --- a/library/Zend/View/Helper/PartialLoop.php +++ b/library/Zend/View/Helper/PartialLoop.php @@ -44,22 +44,14 @@ public function __invoke($name = null, $values = null) return $this; } - if (!is_array($values) - && (!$values instanceof Traversable) - && (is_object($values) && !method_exists($values, 'toArray')) - ) { - throw new Exception\InvalidArgumentException('PartialLoop helper requires iterable data'); - } - - if (is_object($values) - && (!$values instanceof Traversable) - && method_exists($values, 'toArray') - ) { - $values = $values->toArray(); - } - - if ($values instanceof Iterator) { - $values = ArrayUtils::iteratorToArray($values); + if (!is_array($values)) { + if ($values instanceof Traversable) { + $values = ArrayUtils::iteratorToArray($values); + } elseif (is_object($values) && method_exists($values, 'toArray')) { + $values = $values->toArray(); + } else { + throw new Exception\InvalidArgumentException('PartialLoop helper requires iterable data'); + } } // reset the counter if it's called again diff --git a/tests/ZendTest/View/Helper/PartialLoopTest.php b/tests/ZendTest/View/Helper/PartialLoopTest.php index cf3ad4b64cc..e70eff074b5 100644 --- a/tests/ZendTest/View/Helper/PartialLoopTest.php +++ b/tests/ZendTest/View/Helper/PartialLoopTest.php @@ -156,6 +156,19 @@ public function testPartialLoopThrowsExceptionWithBadIterator() } } + /** + * @return void + */ + public function testPassingNullDataThrowsExcpetion() + { + $view = new View(); + $view->resolver()->addPath($this->basePath . '/application/views/scripts'); + $this->helper->setView($view); + + $this->setExpectedException('Zend\View\Exception\InvalidArgumentException'); + $result = $this->helper->__invoke('partialLoop.phtml', null); + } + public function testPassingNoArgsReturnsHelperInstance() { $test = $this->helper->__invoke();