Skip to content

Commit

Permalink
Fixes laminas#7 Fix Placeholder view helper return value
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik authored and gsteel committed Mar 23, 2022
1 parent dceb7b6 commit 4ad9ca5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Helper/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class Placeholder extends AbstractHelper
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;
Expand Down
22 changes: 22 additions & 0 deletions test/Helper/PlaceholderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ public function testSetView(): void
$this->assertSame($view, $this->placeholder->getView());
}

public function testContainerExists(): void
{
$this->placeholder->__invoke('foo');
$containerExists = $this->placeholder->__invoke()->containerExists('foo');

$this->assertTrue($containerExists);
}

public function testPlaceholderRetrievesContainer(): void
{
$container = $this->placeholder->__invoke('foo');
$this->assertInstanceOf(AbstractContainer::class, $container);
}

public function testPlaceholderRetrievesItself(): void
{
$container = $this->placeholder->__invoke();
$this->assertSame($container, $this->placeholder);
}

public function testPlaceholderRetrievesSameContainerOnSubsequentCalls(): void
{
$container1 = $this->placeholder->__invoke('foo');
Expand Down Expand Up @@ -67,4 +81,12 @@ public function testClearContainersRemovesAllContainers(): void
$this->assertFalse($this->placeholder->containerExists('foo'));
$this->assertFalse($this->placeholder->containerExists('bar'));
}

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

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

0 comments on commit 4ad9ca5

Please sign in to comment.