Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/4546'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/Helper/PartialLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/Helper/PartialLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6e2f420

Please sign in to comment.