From 0e13331bb98a9e863cd5adbad1f4ee2f136d2616 Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Sat, 23 Dec 2023 23:32:07 +0100 Subject: [PATCH] add trait unit tests --- tests/phpunit/Traits/XmlTraitTest.php | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/phpunit/Traits/XmlTraitTest.php diff --git a/tests/phpunit/Traits/XmlTraitTest.php b/tests/phpunit/Traits/XmlTraitTest.php new file mode 100644 index 00000000..1efe54e5 --- /dev/null +++ b/tests/phpunit/Traits/XmlTraitTest.php @@ -0,0 +1,57 @@ +'); + + $attr = $this->getAttribute('attr1', $xmlNode); + + $this->assertEquals('attr1', $attr->getName()); + $this->assertEquals('value1', $attr->getValue()); + } + + /** + * @return void + */ + public function testGetAttributeNotFoundLeadsToEmpty(): void + { + $xmlNode = new SimpleXMLElement(''); + + $attr = $this->getAttribute('notExisting', $xmlNode); + + $this->assertEquals('notExisting', $attr->getName()); + $this->assertEquals('', $attr->getValue()); + } + + /** + * @return void + */ + public function testGetAttributes(): void + { + $xmlNode = new SimpleXMLElement(''); + + $attributes = $this->getAttributes($xmlNode); + + $this->assertCount(2, $attributes); + + $this->assertEquals('attr1', $attributes[0]->getName()); + $this->assertEquals('value1', $attributes[0]->getValue()); + + $this->assertEquals('attr2', $attributes[1]->getName()); + $this->assertEquals('value2', $attributes[1]->getValue()); + } +}