Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
andaniel05 committed Apr 22, 2020
1 parent 107e6d5 commit 1f96a10
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/HtmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ class HtmlElement extends AbstractCompositeView implements DependencyInterface
{
use EditableDependencyTrait;

protected $tagName = 'div';
protected $attributes = [];
protected $endTag = true;
protected $selfClosingTag = false;
protected $tagName;
protected $attributes;
protected $endTag;
protected $selfClosingTag;

public function __construct(string $tagName = 'div', ?array $attributes = [], ?string $innerHtml = '', bool $endTag = true, bool $selfClosingTag = false)
{
$this->setTagName($tagName);
$this->setEndTag($endTag);
$this->setSelfClosingTag($selfClosingTag);

if (is_array($attributes)) {
$this->setAttributes($attributes);
}

if ($innerHtml) {
$this->setInnerHtml($innerHtml);
}
}

public function setName(?string $name): void
{
Expand Down
68 changes: 68 additions & 0 deletions tests/HtmlElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,73 @@
});
});
});

testCase('testing constructor', function () {
test(function () {
$tagName = uniqid();
$attributes = range(0, mt_rand(0, 10));
$innerHtml = uniqid();
$endTag = boolval(mt_rand(0, 1));
$selfClosingTag = boolval(mt_rand(0, 1));

$element = $this->getMockBuilder(HtmlElement::class)
->disableOriginalConstructor()
->setMethods([
'setTagName',
'setAttributes',
'setInnerHtml',
'setEndTag',
'setSelfClosingTag',
])
->getMock();
$element->expects($this->once())
->method('setTagName')
->with($this->equalTo($tagName));
$element->expects($this->once())
->method('setAttributes')
->with($this->equalTo($attributes));
$element->expects($this->once())
->method('setInnerHtml')
->with($this->equalTo($innerHtml));
$element->expects($this->once())
->method('setEndTag')
->with($this->equalTo($endTag));
$element->expects($this->once())
->method('setSelfClosingTag')
->with($this->equalTo($selfClosingTag));

$element->__construct($tagName, $attributes, $innerHtml, $endTag, $selfClosingTag);
});

test(function () {
$tagName = uniqid();
$endTag = boolval(mt_rand(0, 1));
$selfClosingTag = boolval(mt_rand(0, 1));

$element = $this->getMockBuilder(HtmlElement::class)
->disableOriginalConstructor()
->setMethods([
'setTagName',
'setAttributes',
'setInnerHtml',
'setEndTag',
'setSelfClosingTag',
])
->getMock();
$element->expects($this->once())
->method('setTagName')
->with($this->equalTo($tagName));
$element->expects($this->never())->method('setAttributes');
$element->expects($this->never())->method('setInnerHtml');
$element->expects($this->once())
->method('setEndTag')
->with($this->equalTo($endTag));
$element->expects($this->once())
->method('setSelfClosingTag')
->with($this->equalTo($selfClosingTag));

$element->__construct($tagName, null, '', $endTag, $selfClosingTag);
});
});
});
});

0 comments on commit 1f96a10

Please sign in to comment.