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

Fix Placeholder view helper return value #162

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 2 additions & 6 deletions src/Helper/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\View\Helper;

use Zend\View\Exception\InvalidArgumentException;
use Zend\View\Helper\Placeholder\Container;

/**
Expand Down Expand Up @@ -37,15 +36,12 @@ class Placeholder extends AbstractHelper
* Placeholder helper
*
* @param string $name
* @throws InvalidArgumentException
* @return Placeholder\Container\AbstractContainer
* @return Placeholder\Container\AbstractContainer|self
*/
public function __invoke($name = null)
{
if ($name === null) {
throw new InvalidArgumentException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular change is most likely a BC break. Although I don't think people actually do rely on try-catching it, it is possible that they rely on the page to be crashing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you. Should we move this to the 3.0.0 milestone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius ping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thexpand
Next major version makes sense, because nobody uses a try-catch-block here.

'Placeholder: missing argument. $name is required by placeholder($name)'
);
return $this;
}

$name = (string) $name;
Expand Down
31 changes: 31 additions & 0 deletions test/Helper/PlaceholderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public function testSetView()
$this->assertSame($view, $this->placeholder->getView());
}

/**
* @return void
*/
public function testContainerExists()
{
$this->placeholder->__invoke('foo');
$containerExists = $this->placeholder->__invoke()->containerExists('foo');

$this->assertTrue($containerExists);
}

/**
* @return void
*/
Expand All @@ -68,6 +79,15 @@ public function testPlaceholderRetrievesContainer()
$this->assertInstanceOf(AbstractContainer::class, $container);
}

/**
* @return void
*/
public function testPlaceholderRetrievesItself()
{
$container = $this->placeholder->__invoke();
$this->assertSame($container, $this->placeholder);
}

/**
* @return void
*/
Expand All @@ -77,4 +97,15 @@ public function testPlaceholderRetrievesSameContainerOnSubsequentCalls()
$container2 = $this->placeholder->__invoke('foo');
$this->assertSame($container1, $container2);
}

/**
* @return void
*/
public function testGetContainerRetrievesTheCorrectContainer()
{
$container1 = $this->placeholder->__invoke('foo');
$container2 = $this->placeholder->__invoke()->getContainer('foo');

$this->assertSame($container1, $container2);
}
}