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

Commit

Permalink
Merge e1a3bfe into a2d2751
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 26, 2015
2 parents a2d2751 + e1a3bfe commit 8a99dad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/View/Helper/FormCollection.php
Expand Up @@ -15,7 +15,7 @@
use Zend\Form\Element\Collection as CollectionElement;
use Zend\Form\FieldsetInterface;
use Zend\Form\LabelAwareInterface;
use Zend\View\Helper\AbstractHelper as BaseAbstractHelper;
use Zend\View\Helper\HelperInterface;

class FormCollection extends AbstractHelper
{
Expand Down Expand Up @@ -57,14 +57,14 @@ class FormCollection extends AbstractHelper
/**
* The view helper used to render sub elements.
*
* @var AbstractHelper
* @var HelperInterface
*/
protected $elementHelper;

/**
* The view helper used to render sub fieldsets.
*
* @var AbstractHelper
* @var HelperInterface
*/
protected $fieldsetHelper;

Expand Down Expand Up @@ -236,10 +236,10 @@ public function getDefaultElementHelper()
/**
* Sets the element helper that should be used by this collection.
*
* @param AbstractHelper $elementHelper The element helper to use.
* @param HelperInterface $elementHelper The element helper to use.
* @return FormCollection
*/
public function setElementHelper(AbstractHelper $elementHelper)
public function setElementHelper(HelperInterface $elementHelper)
{
$this->elementHelper = $elementHelper;
return $this;
Expand All @@ -248,7 +248,7 @@ public function setElementHelper(AbstractHelper $elementHelper)
/**
* Retrieve the element helper.
*
* @return AbstractHelper
* @return HelperInterface
* @throws RuntimeException
*/
protected function getElementHelper()
Expand All @@ -261,9 +261,8 @@ protected function getElementHelper()
$this->elementHelper = $this->view->plugin($this->getDefaultElementHelper());
}

if (!$this->elementHelper instanceof BaseAbstractHelper) {
// @todo Ideally the helper should implement an interface.
throw new RuntimeException('Invalid element helper set in FormCollection. The helper must be an instance of AbstractHelper.');
if (!$this->elementHelper instanceof HelperInterface) {
throw new RuntimeException('Invalid element helper set in FormCollection. The helper must be an instance of Zend\View\Helper\HelperInterface.');
}

return $this->elementHelper;
Expand All @@ -272,10 +271,10 @@ protected function getElementHelper()
/**
* Sets the fieldset helper that should be used by this collection.
*
* @param AbstractHelper $fieldsetHelper The fieldset helper to use.
* @param HelperInterface $fieldsetHelper The fieldset helper to use.
* @return FormCollection
*/
public function setFieldsetHelper(AbstractHelper $fieldsetHelper)
public function setFieldsetHelper(HelperInterface $fieldsetHelper)
{
$this->fieldsetHelper = $fieldsetHelper;
return $this;
Expand Down
10 changes: 10 additions & 0 deletions test/View/Helper/FormCollectionTest.php
Expand Up @@ -402,4 +402,14 @@ public function testCanDisableLabelHtmlEscape()
$markup = $this->helper->render($collection);
$this->assertRegexp('#<fieldset(.*?)><legend><strong>Some label</strong><\/legend>(.*?)<\/fieldset>#', $markup);
}

public function testForElementHelperNotInstanceOfHelperInterface()
{
$this->setExpectedException('RuntimeException', 'Invalid element helper set in FormCollection. The helper must be an instance of Zend\View\Helper\HelperInterface.');

$method = new \ReflectionMethod('Zend\Form\View\Helper\FormCollection', 'getElementHelper');
$method->setAccessible(true);

$method->invokeArgs(new FormCollectionHelper(), array());
}
}

0 comments on commit 8a99dad

Please sign in to comment.