diff --git a/src/Tag.php b/src/Tag.php
index 6aa8873..f85a61a 100644
--- a/src/Tag.php
+++ b/src/Tag.php
@@ -65,14 +65,19 @@ class Tag
/**
* Tag constructor.
*
- * @param string $name The tag name.
+ * @param string $name The tag name.
+ * @param array $attributes The tag attributes, as an associative array of names to values. Optional.
*/
- public function __construct(string $name)
+ public function __construct(string $name, array $attributes = [])
{
$name = strtolower($name);
$this->name = $name;
$this->isVoid = in_array($name, self::VOID_ELEMENTS, true);
+
+ if ($attributes) {
+ $this->setAttributes($attributes);
+ }
}
/**
diff --git a/tests/TagTest.php b/tests/TagTest.php
index dd59429..7e2f937 100644
--- a/tests/TagTest.php
+++ b/tests/TagTest.php
@@ -34,14 +34,14 @@ public function testTag()
public function testVoidTag()
{
- $tag = new Tag('IMG');
- $this->assertSame('', $tag->render());
+ $tag = new Tag('IMG', ['SRC' => 'TEST.PNG']);
+ $this->assertSame('', $tag->render());
$tag->setAttributes([
'ID' => 123,
'Src' => 'IMAGE.PNG',
'Data-Chars' => '"\'<>'
]);
- $this->assertSame('', $tag->render());
+ $this->assertSame('', $tag->render());
}
}