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

Commit 06642a0

Browse files
committed
Add test for check empty placeholder container items.
1 parent 19a8b3e commit 06642a0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Helper/Placeholder/Container/AbstractContainer.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ public function toString($indent = null)
117117
? $this->getWhitespace($indent)
118118
: $this->getIndent();
119119

120-
$items = $this->getArrayCopy();
121120
// If we don't have items - do not show prefix and postfix
122-
if (!count($items)) {
121+
if (!$this->count()) {
123122
return '';
124123
}
124+
125+
$itemsToString = implode($this->getSeparator(), $this->getArrayCopy());
126+
// todo check empty $itemsToString after trim() to return ''
127+
125128
$return = $indent
126129
. $this->getPrefix()
127-
. implode($this->getSeparator(), $items)
130+
. $itemsToString
128131
. $this->getPostfix();
129132
$return = preg_replace("/(\r\n?|\n)/", '$1' . $indent, $return);
130133

test/Helper/Placeholder/ContainerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,13 @@ public function testIndentationIsHonored()
432432
$this->assertContains(" <ul>\n", $string, $string);
433433
$this->assertContains("\n </ul>", $string, $string);
434434
}
435+
436+
public function testNoUsePrefixPostfixIfNoItems()
437+
{
438+
$this->container->setPrefix("<h1>")
439+
->setPostfix("</h1>");
440+
$string = $this->container->toString();
441+
$this->assertEquals('', $string);
442+
}
443+
435444
}

0 commit comments

Comments
 (0)