diff --git a/src/TestUtils/SerializableElementTestTrait.php b/src/TestUtils/SerializableElementTestTrait.php index 4fb7d9c..27736a1 100644 --- a/src/TestUtils/SerializableElementTestTrait.php +++ b/src/TestUtils/SerializableElementTestTrait.php @@ -22,6 +22,38 @@ trait SerializableElementTestTrait protected static DOMDocument $xmlRepresentation; + /** + * Test creating XML from a class. + */ + abstract public function testMarshalling(): void; + + + /** + * Test creating a class from XML. + */ + public function testUnmarshalling(): void + { + if (!class_exists(self::$testedClass)) { + $this->markTestSkipped( + 'Unable to run ' . self::class . '::testUnmarshalling(). Please set ' . self::class + . ':$testedClass to a class-string representing the XML-class being tested', + ); + } elseif (empty(self::$xmlRepresentation)) { + $this->markTestSkipped( + 'Unable to run ' . self::class . '::testUnmarshalling(). Please set ' . self::class + . ':$xmlRepresentation to a DOMDocument representing the XML-class being tested', + ); + } else { + $elt = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($elt), + ); + } + } + + /** * Test serialization / unserialization. * @@ -47,10 +79,4 @@ public function testSerialization(): void ); } } - - - abstract public function testMarshalling(): void; - - - abstract public function testUnmarshalling(): void; } diff --git a/tests/XML/AbstractElementTest.php b/tests/XML/AbstractElementTest.php index cf6a330..97906ec 100644 --- a/tests/XML/AbstractElementTest.php +++ b/tests/XML/AbstractElementTest.php @@ -54,6 +54,7 @@ public function testMarshalling(): void /** */ + #[Override] public function testUnmarshalling(): void { $element = Element::fromXML(self::$xmlRepresentation->documentElement); diff --git a/tests/XML/Base64ElementTraitTest.php b/tests/XML/Base64ElementTraitTest.php index 8b5e140..0640fbe 100644 --- a/tests/XML/Base64ElementTraitTest.php +++ b/tests/XML/Base64ElementTraitTest.php @@ -57,6 +57,7 @@ public function testMarshalling(): void /** */ + #[Override] public function testUnmarshalling(): void { $base64Element = Base64Element::fromXML(self::$xmlRepresentation->documentElement); diff --git a/tests/XML/ChunkTest.php b/tests/XML/ChunkTest.php index 97fd7f6..153c78f 100644 --- a/tests/XML/ChunkTest.php +++ b/tests/XML/ChunkTest.php @@ -53,6 +53,7 @@ public function testMarshalling(): void /** */ + #[Override] public function testUnmarshalling(): void { $element = Chunk::fromXML(self::$xmlRepresentation->documentElement); diff --git a/tests/XML/ExtendableAttributesTest.php b/tests/XML/ExtendableAttributesTest.php index 833d174..2cfe820 100644 --- a/tests/XML/ExtendableAttributesTest.php +++ b/tests/XML/ExtendableAttributesTest.php @@ -57,17 +57,4 @@ public function testMarshalling(): void strval($extendableElement), ); } - - - /** - */ - public function testUnmarshalling(): void - { - $extendableElement = ExtendableAttributesElement::fromXML(self::$xmlRepresentation->documentElement); - - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($extendableElement), - ); - } } diff --git a/tests/XML/ExtendableElementTest.php b/tests/XML/ExtendableElementTest.php index 73f32b9..8e5238c 100644 --- a/tests/XML/ExtendableElementTest.php +++ b/tests/XML/ExtendableElementTest.php @@ -58,17 +58,4 @@ public function testMarshalling(): void strval($extendableElement), ); } - - - /** - */ - public function testUnmarshalling(): void - { - $extendableElement = ExtendableElement::fromXML(self::$xmlRepresentation->documentElement); - - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($extendableElement), - ); - } } diff --git a/tests/XML/LocalizedStringElementTraitTest.php b/tests/XML/LocalizedStringElementTraitTest.php index c7bba0d..968b8e5 100644 --- a/tests/XML/LocalizedStringElementTraitTest.php +++ b/tests/XML/LocalizedStringElementTraitTest.php @@ -50,15 +50,4 @@ public function testMarshalling(): void strval($localizedStringElement), ); } - - - /** - */ - public function testUnmarshalling(): void - { - $localizedStringElement = LocalizedStringElement::fromXML(self::$xmlRepresentation->documentElement); - - $this->assertEquals('en', $localizedStringElement->getLanguage()); - $this->assertEquals('test', $localizedStringElement->getContent()); - } } diff --git a/tests/XML/QNameElementTraitTest.php b/tests/XML/QNameElementTraitTest.php index 9607565..35f2fa2 100644 --- a/tests/XML/QNameElementTraitTest.php +++ b/tests/XML/QNameElementTraitTest.php @@ -76,17 +76,6 @@ public function testMarshallingInvalidQualifiedNameThrowsException(): void } - /** - */ - public function testUnmarshalling(): void - { - $qnameElement = QNameElement::fromXML(self::$xmlRepresentation->documentElement); - - $this->assertEquals('env:Sender', $qnameElement->getContent()); - $this->assertEquals('http://www.w3.org/2003/05/soap-envelope', $qnameElement->getContentNamespaceUri()); - } - - /** */ public function testUnmarshallingNonNamepacedQualifiedName(): void diff --git a/tests/XML/StringElementTraitTest.php b/tests/XML/StringElementTraitTest.php index e8c17de..14893ab 100644 --- a/tests/XML/StringElementTraitTest.php +++ b/tests/XML/StringElementTraitTest.php @@ -50,14 +50,4 @@ public function testMarshalling(): void strval($stringElement), ); } - - - /** - */ - public function testUnmarshalling(): void - { - $stringElement = StringElement::fromXML(self::$xmlRepresentation->documentElement); - - $this->assertEquals('test', $stringElement->getContent()); - } }