diff --git a/src/Helper/Placeholder.php b/src/Helper/Placeholder.php index aad16d4c..fb7794d9 100644 --- a/src/Helper/Placeholder.php +++ b/src/Helper/Placeholder.php @@ -9,7 +9,6 @@ namespace Zend\View\Helper; -use Zend\View\Exception\InvalidArgumentException; use Zend\View\Helper\Placeholder\Container; /** @@ -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( - 'Placeholder: missing argument. $name is required by placeholder($name)' - ); + return $this; } $name = (string) $name; diff --git a/test/Helper/PlaceholderTest.php b/test/Helper/PlaceholderTest.php index 4d7ac5d6..396332ad 100644 --- a/test/Helper/PlaceholderTest.php +++ b/test/Helper/PlaceholderTest.php @@ -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 */ @@ -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 */ @@ -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); + } }