From 4819753b4b6f94304d3b9c9b68b953e9f3929ae8 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 29 May 2026 14:39:33 +0000 Subject: [PATCH 1/4] fix phpstan.failing tests. --- src/XML/Container/AbstractTestContainer.php | 4 + src/XML/Container/XMLSchemaElementsTrait.php | 2 +- src/XML/DOMDocumentFactory.php | 154 +++++++++++++----- src/XML/ExtendableAttributesTrait.php | 8 + .../SerializableElementTestTrait.php | 22 ++- src/XPath/XPath.php | 6 +- tests/XML/AbstractElementTest.php | 14 +- tests/XML/ChunkTest.php | 12 +- tests/XML/DOMDocumentFactoryTest.php | 6 +- tests/XML/ExtendableAttributesTest.php | 10 +- tests/XML/ExtendableElementTest.php | 10 +- tests/XPath/XPathTest.php | 2 - 12 files changed, 190 insertions(+), 60 deletions(-) diff --git a/src/XML/Container/AbstractTestContainer.php b/src/XML/Container/AbstractTestContainer.php index 0d96ef82..45b708ff 100644 --- a/src/XML/Container/AbstractTestContainer.php +++ b/src/XML/Container/AbstractTestContainer.php @@ -31,5 +31,9 @@ abstract public function getLanguageValue(string $language = 'en'): LanguageValu abstract public function getXMLAttribute(int $x = 1): XMLAttribute; + /** + * @param non-empty-string $text + * @return \Dom\NodeList<\Dom\Node> + */ abstract public function getDOMText(string $text): Dom\NodeList; } diff --git a/src/XML/Container/XMLSchemaElementsTrait.php b/src/XML/Container/XMLSchemaElementsTrait.php index 15f46802..73ee6ce2 100644 --- a/src/XML/Container/XMLSchemaElementsTrait.php +++ b/src/XML/Container/XMLSchemaElementsTrait.php @@ -26,7 +26,7 @@ trait XMLSchemaElementsTrait /** @var array */ protected array $appinfo = []; - /** @var array */ + /** @var array */ protected array $domText = []; diff --git a/src/XML/DOMDocumentFactory.php b/src/XML/DOMDocumentFactory.php index 41f35dba..a80a7603 100644 --- a/src/XML/DOMDocumentFactory.php +++ b/src/XML/DOMDocumentFactory.php @@ -12,7 +12,8 @@ use SimpleSAML\XPath\XPath; use function file_get_contents; -use function func_num_args; +use function restore_error_handler; +use function set_error_handler; use function sprintf; use function strpos; @@ -22,19 +23,50 @@ final class DOMDocumentFactory { /** + * Base libxml options used when parsing XML. + * + * Note: We add LIBXML_NO_XXE automatically when available (libxml >= 2.13.0). + * * @var non-negative-int - * TODO: Add LIBXML_NO_XXE to the defaults when libxml 2.13.0 become generally available */ - public const int DEFAULT_OPTIONS = \LIBXML_COMPACT | \LIBXML_NOENT | \LIBXML_NONET | \LIBXML_NSCLEAN; + public const int DEFAULT_OPTIONS_BASE = \LIBXML_COMPACT | \LIBXML_NOENT | \LIBXML_NONET | \LIBXML_NSCLEAN; /** - * @param string $xml - * @param non-negative-int $options + * @return non-negative-int + */ + public static function getDefaultOptions(): int + { + $options = self::DEFAULT_OPTIONS_BASE; + + // Add LIBXML_NO_XXE to the defaults when available (libxml >= 2.13.0) + if (defined('LIBXML_NO_XXE')) { + $options |= \LIBXML_NO_XXE; + } + + return $options; + } + + + /** + * Create a DOM XML document from an XML string. + * + * The input is validated to reject potentially dangerous constructs (e.g. DOCTYPE). + * Parser warnings/notices are converted into {@see \DOMException}. + * + * @param non-empty-string $xml XML document as a string. + * @param non-negative-int|null $options Libxml parser options. If {@see null}, default options will be used + * (including {@see \LIBXML_NO_XXE} when available). + * + * @return \Dom\XMLDocument + * + * @throws \SimpleSAML\Assert\AssertionFailedException If $xml is empty/whitespace-only or contains a DOCTYPE. + * @throws \SimpleSAML\XML\Exception\RuntimeException If dangerous XML is detected (DOCTYPE is not allowed). + * @throws \DOMException If parsing emits warnings/notices or fails. */ public static function fromString( string $xml, - int $options = self::DEFAULT_OPTIONS, + ?int $options = null, ): Dom\XMLDocument { Assert::notWhitespaceOnly($xml); Assert::notRegex( @@ -44,13 +76,25 @@ public static function fromString( RuntimeException::class, ); - // If LIBXML_NO_XXE is available and option not set - if (func_num_args() === 1 && defined('LIBXML_NO_XXE')) { - $options |= \LIBXML_NO_XXE; - } + $options = $options ?? self::getDefaultOptions(); $domDocument = self::create(); - $loaded = $domDocument->createFromString($xml, $options); + + // Convert parser warnings/notices into DOMException to avoid PHP warnings leaking into test output + set_error_handler( + /** + * @throws \DOMException + */ + static function (int $severity, string $message): never { + throw new \DOMException($message); + }, + ); + + try { + $loaded = $domDocument->createFromString($xml, $options); + } finally { + restore_error_handler(); + } foreach ($domDocument->childNodes as $child) { Assert::false( @@ -65,12 +109,25 @@ public static function fromString( /** - * @param string $file - * @param non-negative-int $options + * Create a DOM XML document from an XML file. + * + * The file is read into a string and then parsed using {@see self::fromString()}. + * + * @param non-empty-string $file Path to the XML file. + * @param non-negative-int|null $options Libxml parser options. If {@see null}, default options will be used + * (including {@see \LIBXML_NO_XXE} when available). + * + * @return \Dom\XMLDocument + * + * @throws \SimpleSAML\XML\Exception\IOException If the file cannot be read. + * @throws \SimpleSAML\Assert\AssertionFailedException If the file content is empty/whitespace-only + * or contains a DOCTYPE. + * @throws \SimpleSAML\XML\Exception\RuntimeException If dangerous XML is detected (DOCTYPE is not allowed). + * @throws \DOMException If parsing emits warnings/notices or fails. */ public static function fromFile( string $file, - int $options = self::DEFAULT_OPTIONS, + ?int $options = null, ): Dom\XMLDocument { error_clear_last(); $xml = @file_get_contents($file); @@ -82,7 +139,8 @@ public static function fromFile( } Assert::notWhitespaceOnly($xml, sprintf('File "%s" does not have content', $file), RuntimeException::class); - return (func_num_args() < 2) ? static::fromString($xml) : static::fromString($xml, $options); + + return static::fromString($xml, $options); } @@ -96,18 +154,31 @@ public static function create(string $encoding = 'UTF-8'): Dom\XMLDocument /** - * @param \Dom\XMLDocument $doc + * Normalize namespace declarations in an XML document. + * + * This method collects namespace declarations required by prefixed elements and moves the corresponding + * {@code xmlns:prefix} declarations to the document root, removing {@code xmlns} / {@code xmlns:*} attributes + * from descendant elements. + * + * Note: this mutates the provided document and is not a substitute for XML canonicalization (C14N). + * + * @param \Dom\XMLDocument $doc The XML document to normalize. + * + * @return \Dom\XMLDocument The same document instance, potentially modified. If the document has no root element + * or no namespace declarations to normalize, it is returned unchanged. */ public static function normalizeDocument(Dom\XMLDocument $doc): Dom\XMLDocument { // Get the root element $root = $doc->documentElement; + if ($root === null) { + return $doc; + } - // Collect all xmlns attributes from the document $xpath = XPath::getXPath($doc); $xmlnsAttributes = []; - // Register all namespaces to ensure XPath can handle them + // Collect namespace declarations needed for prefixed elements in the document foreach ($xpath->query('//*[namespace::*]') as $node) { if ($node instanceof Dom\Element) { $name = 'xmlns:' . $node->prefix; @@ -123,40 +194,45 @@ public static function normalizeDocument(Dom\XMLDocument $doc): Dom\XMLDocument return $doc; } - // Remove xmlns attributes from all elements - $nodes = $xpath->query('//*[namespace::*]'); - foreach ($nodes as $node) { - if ($node instanceof Dom\Element) { - $attributesToRemove = []; - foreach ($node->attributes as $attr) { - if (strpos($attr->nodeName, 'xmlns') === 0 || $attr->nodeName === 'xmlns') { - $attributesToRemove[] = $attr->namespaceURI; - } + // Remove xmlns attributes from all elements (proper XMLNS namespace removal) + foreach ($xpath->query('//*[namespace::*]') as $node) { + if (!$node instanceof Dom\Element) { + continue; + } + + foreach ($node->attributes as $attr) { + if ($attr->namespaceURI === C::NS_XMLNS) { + $node->removeAttributeNS(C::NS_XMLNS, $attr->localName); + continue; } - foreach ($attributesToRemove as $attrName) { - $node->removeAttribute($attrName); + if (strpos($attr->nodeName, 'xmlns') === 0 || $attr->nodeName === 'xmlns') { + // Fallback for implementations that still expose xmlns attrs without namespaceURI + $node->removeAttribute($attr->nodeName); } } } // Add all collected xmlns attributes to the root element foreach ($xmlnsAttributes as $name => $value) { - $root->setAttribute($name, $value); + $root->setAttributeNS(C::NS_XMLNS, $name, $value); } - // Get the normalized string - /** @var \Dom\XMLDocument $ownerDocument */ - $ownerDocument = $root->ownerDocument; - - // Return the normalized XML - return static::fromString($ownerDocument->saveXml($ownerDocument->documentElement)); + return $doc; } /** - * @param \Dom\Element $elt - * @param string|null $prefix + * Resolve a namespace URI for a given prefix in the context of an element. + * + * The reserved prefixes {@code xml} and {@code xmlns} are mapped to their well-known namespace URIs. + * For all other prefixes, this method inspects the in-scope namespaces of the document element. + * + * @param \Dom\Element $elt An element belonging to the document whose in-scope namespaces will be consulted. + * @param string|null $prefix The namespace prefix to resolve. Use {@see null} to resolve the default namespace. + * + * @return string|null The namespace URI associated with the given prefix, or {@see null} + * if the prefix is not bound. */ public static function lookupNamespaceURI(Dom\Element $elt, ?string $prefix): ?string { @@ -167,11 +243,9 @@ public static function lookupNamespaceURI(Dom\Element $elt, ?string $prefix): ?s return C::NS_XMLNS; } - /** @var \Dom\NamespaceInfo[] $namespaces */ $namespaces = $elt->ownerDocument->documentElement->getInScopeNamespaces(); - $xmlnsAttributes = []; foreach ($namespaces as $ns) { if ($ns->prefix === $prefix) { return $ns->namespaceURI; diff --git a/src/XML/ExtendableAttributesTrait.php b/src/XML/ExtendableAttributesTrait.php index 2f0d5997..4c237aec 100644 --- a/src/XML/ExtendableAttributesTrait.php +++ b/src/XML/ExtendableAttributesTrait.php @@ -109,6 +109,10 @@ protected static function getAttributesNSFromXML( Assert::oneOf($namespace, NS::$PREDEFINED); foreach ($xml->attributes as $a) { + if ($a->namespaceURI === 'http://www.w3.org/2000/xmlns/') { + continue; + } + if ( $exclusionList && (in_array([$a->namespaceURI, $a->localName], $exclusionList, true) @@ -148,6 +152,10 @@ protected static function getAttributesNSFromXML( } foreach ($xml->attributes as $a) { + if ($a->namespaceURI === 'http://www.w3.org/2000/xmlns/') { + continue; + } + if (in_array([$a->namespaceURI, $a->localName], $exclusionList, true)) { continue; } elseif (!in_array($a->namespaceURI, $namespace, true)) { diff --git a/src/XML/TestUtils/SerializableElementTestTrait.php b/src/XML/TestUtils/SerializableElementTestTrait.php index 80f1c15b..12d7ea2a 100644 --- a/src/XML/TestUtils/SerializableElementTestTrait.php +++ b/src/XML/TestUtils/SerializableElementTestTrait.php @@ -5,9 +5,12 @@ namespace SimpleSAML\XML\TestUtils; use Dom; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\Attributes\Depends; +use SimpleSAML\XML\DOMDocumentFactory; use function class_exists; +use function strval; /** * Test for Serializable XML classes to perform default serialization tests. @@ -48,7 +51,7 @@ public function testUnmarshalling(): void } else { $elt = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement); - $this->assertEquals( + $this->assertXmlStringEquals( self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), strval($elt), ); @@ -74,10 +77,25 @@ public function testSerialization(): void . ':$xmlRepresentation to a DOMDocument representing the XML-class being tested', ); } else { - $this->assertEquals( + $this->assertXmlStringEquals( self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), strval(unserialize(serialize(self::$testedClass::fromXML(self::$xmlRepresentation->documentElement)))), ); } } + + + private function assertXmlStringEquals(string $expectedXml, string $actualXml): void + { + $expectedDoc = DOMDocumentFactory::fromString($expectedXml); + $actualDoc = DOMDocumentFactory::fromString($actualXml); + + Assert::assertNotNull($expectedDoc->documentElement); + Assert::assertNotNull($actualDoc->documentElement); + + Assert::assertSame( + $expectedDoc->documentElement->C14N(), + $actualDoc->documentElement->C14N(), + ); + } } diff --git a/src/XPath/XPath.php b/src/XPath/XPath.php index f3a81a86..e8cc7b3c 100644 --- a/src/XPath/XPath.php +++ b/src/XPath/XPath.php @@ -125,7 +125,11 @@ private static function registerAncestorNamespaces(Dom\XPath $xp, Dom\Node $node $uri = (string) $attr->nodeValue; if ( - $prefix === '' || $prefix === null || $prefix === 'xmlns' || $uri === '' || isset($prefixToUri[$prefix]) + $prefix === '' + || $prefix === null + || $prefix === 'xmlns' + || $uri === '' + || isset($prefixToUri[$prefix]) ) { continue; } diff --git a/tests/XML/AbstractElementTest.php b/tests/XML/AbstractElementTest.php index 25154d36..f667e9b6 100644 --- a/tests/XML/AbstractElementTest.php +++ b/tests/XML/AbstractElementTest.php @@ -52,9 +52,15 @@ public function testMarshalling(): void StringValue::fromString('otherText'), ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - $element, + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $actualXml = strval($element); + + $expectedDoc = DOMDocumentFactory::fromString($expectedXml); + $actualDoc = DOMDocumentFactory::fromString($actualXml); + + $this->assertSame( + $expectedDoc->documentElement->C14N(), + $actualDoc->documentElement->C14N(), ); } @@ -88,7 +94,7 @@ public function testGetAttribute(): void $this->assertEquals('2', Element::getAttribute($xml, 'integer', IntegerValue::class)); // Get optional attributes - $this->assertEquals('text', Element::getOptionalAttribute($xml, 'text', StringValue::Class)); + $this->assertEquals('text', Element::getOptionalAttribute($xml, 'text', StringValue::class)); $this->assertEquals('otherText', Element::getOptionalAttribute($xml, 'otherText', StringValue::class)); $this->assertEquals('false', Element::getOptionalAttribute($xml, 'boolean', BooleanValue::class)); $this->assertEquals('2', Element::getOptionalAttribute($xml, 'integer', IntegerValue::class)); diff --git a/tests/XML/ChunkTest.php b/tests/XML/ChunkTest.php index a5d4017d..caea3376 100644 --- a/tests/XML/ChunkTest.php +++ b/tests/XML/ChunkTest.php @@ -48,9 +48,15 @@ public function testMarshalling(): void $xml = self::$xmlRepresentation->documentElement; $chunk = new Chunk($xml); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($chunk), + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $actualXml = strval($chunk); + + $expectedDoc = DOMDocumentFactory::fromString($expectedXml); + $actualDoc = DOMDocumentFactory::fromString($actualXml); + + $this->assertSame( + $expectedDoc->documentElement->C14N(), + $actualDoc->documentElement->C14N(), ); } diff --git a/tests/XML/DOMDocumentFactoryTest.php b/tests/XML/DOMDocumentFactoryTest.php index 3604ba8e..ac899727 100644 --- a/tests/XML/DOMDocumentFactoryTest.php +++ b/tests/XML/DOMDocumentFactoryTest.php @@ -122,9 +122,9 @@ public function testNormalizeDocument(): void $notNormalized = DOMDocumentFactory::fromFile('tests/resources/xml/domdocument_not_normalized.xml'); $normalizedDoc = DOMDocumentFactory::normalizeDocument($notNormalized); - $this->assertEquals( - $normalized->saveXml($normalized), - $normalizedDoc->saveXml($normalizedDoc), + $this->assertSame( + $normalized->documentElement->C14N(), + $normalizedDoc->documentElement->C14N(), ); } } diff --git a/tests/XML/ExtendableAttributesTest.php b/tests/XML/ExtendableAttributesTest.php index a68ce6bc..1aa14ee2 100644 --- a/tests/XML/ExtendableAttributesTest.php +++ b/tests/XML/ExtendableAttributesTest.php @@ -50,9 +50,15 @@ public function testMarshalling(): void ], ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $actualXml = strval($extendableElement); + + $expectedDoc = DOMDocumentFactory::fromString($expectedXml); + $actualDoc = DOMDocumentFactory::fromString($actualXml); + $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($extendableElement), + $expectedDoc->documentElement->C14N(), + $actualDoc->documentElement->C14N(), ); } diff --git a/tests/XML/ExtendableElementTest.php b/tests/XML/ExtendableElementTest.php index 590a3ae1..a8a024f2 100644 --- a/tests/XML/ExtendableElementTest.php +++ b/tests/XML/ExtendableElementTest.php @@ -61,9 +61,15 @@ public function testMarshalling(): void ], ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $actualXml = strval($extendableElement); + + $expectedDoc = DOMDocumentFactory::fromString($expectedXml); + $actualDoc = DOMDocumentFactory::fromString($actualXml); + $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($extendableElement), + $expectedDoc->documentElement->C14N(), + $actualDoc->documentElement->C14N(), ); } diff --git a/tests/XPath/XPathTest.php b/tests/XPath/XPathTest.php index e059ec56..f88a1f6f 100644 --- a/tests/XPath/XPathTest.php +++ b/tests/XPath/XPathTest.php @@ -10,9 +10,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\RuntimeException; use SimpleSAML\XPath\XPath; -use Throwable; use function libxml_clear_errors; use function libxml_use_internal_errors; From 2d35606307f5ac3497ee61cb664376162552b84a Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 29 May 2026 15:19:15 +0000 Subject: [PATCH 2/4] Fix phpstan-dev execution issues --- tests/XML/AbstractElementTest.php | 48 ++++++++++++++------------ tests/XML/ChunkTest.php | 32 +++++++++++------ tests/XML/DOMDocumentFactoryTest.php | 12 +++++-- tests/XML/ExtendableAttributesTest.php | 30 +++++++++------- tests/XML/ExtendableElementTest.php | 48 +++++++++++++++----------- tests/XPath/XPathTest.php | 2 ++ tools/composer-require-checker.json | 9 ++--- 7 files changed, 110 insertions(+), 71 deletions(-) diff --git a/tests/XML/AbstractElementTest.php b/tests/XML/AbstractElementTest.php index f667e9b6..aa714afe 100644 --- a/tests/XML/AbstractElementTest.php +++ b/tests/XML/AbstractElementTest.php @@ -29,8 +29,6 @@ final class AbstractElementTest extends TestCase use SerializableElementTestTrait; - /** - */ public static function setUpBeforeClass(): void { self::$testedClass = Element::class; @@ -41,8 +39,6 @@ public static function setUpBeforeClass(): void } - /** - */ public function testMarshalling(): void { $element = new Element( @@ -52,25 +48,38 @@ public function testMarshalling(): void StringValue::fromString('otherText'), ); - $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $representationRoot = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $representationRoot); + + $expectedXml = self::$xmlRepresentation->saveXml($representationRoot); + $this->assertNotSame('', $expectedXml); + /** @var non-empty-string $expectedXml */ + $actualXml = strval($element); + $this->assertNotSame('', $actualXml); + /** @var non-empty-string $actualXml */ $expectedDoc = DOMDocumentFactory::fromString($expectedXml); $actualDoc = DOMDocumentFactory::fromString($actualXml); + $expectedRoot = $expectedDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $expectedRoot); + + $actualRoot = $actualDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $actualRoot); + $this->assertSame( - $expectedDoc->documentElement->C14N(), - $actualDoc->documentElement->C14N(), + $expectedRoot->C14N(), + $actualRoot->C14N(), ); } - /** - */ public function testUnmarshalling(): void { - /** @var \Dom\Element $elt */ $elt = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $elt); + $element = Element::fromXML($elt); $this->assertEquals('2', $element->getInteger()); @@ -80,12 +89,10 @@ public function testUnmarshalling(): void } - /** - */ public function testGetAttribute(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); // Get mandatory attributes $this->assertEquals('text', Element::getAttribute($xml, 'text', StringValue::class)); @@ -142,12 +149,11 @@ public function testGetAttribute(): void } - /** - */ public function testGetAttributeThrowsExceptionOnMissingAttribute(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); + $xml = clone $xml; $xml->removeAttribute('text'); @@ -156,12 +162,11 @@ public function testGetAttributeThrowsExceptionOnMissingAttribute(): void } - /** - */ public function testGetBooleanAttributeThrowsExceptionOnMissingAttribute(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); + $xml = clone $xml; $xml->removeAttribute('boolean'); @@ -170,12 +175,11 @@ public function testGetBooleanAttributeThrowsExceptionOnMissingAttribute(): void } - /** - */ public function testGetIntegerAttributeThrowsExceptionOnMissingAttribute(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); + $xml = clone $xml; $xml->removeAttribute('integer'); diff --git a/tests/XML/ChunkTest.php b/tests/XML/ChunkTest.php index caea3376..f8ab3eae 100644 --- a/tests/XML/ChunkTest.php +++ b/tests/XML/ChunkTest.php @@ -28,8 +28,6 @@ final class ChunkTest extends TestCase use SerializableElementTestTrait; - /** - */ public static function setUpBeforeClass(): void { self::$testedClass = Chunk::class; @@ -40,33 +38,45 @@ public static function setUpBeforeClass(): void } - /** - */ public function testMarshalling(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); + $chunk = new Chunk($xml); - $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $representationRoot = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $representationRoot); + + $expectedXml = self::$xmlRepresentation->saveXml($representationRoot); + $this->assertNotSame('', $expectedXml); + /** @var non-empty-string $expectedXml */ + $actualXml = strval($chunk); + $this->assertNotSame('', $actualXml); + /** @var non-empty-string $actualXml */ $expectedDoc = DOMDocumentFactory::fromString($expectedXml); $actualDoc = DOMDocumentFactory::fromString($actualXml); + $expectedRoot = $expectedDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $expectedRoot); + + $actualRoot = $actualDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $actualRoot); + $this->assertSame( - $expectedDoc->documentElement->C14N(), - $actualDoc->documentElement->C14N(), + $expectedRoot->C14N(), + $actualRoot->C14N(), ); } - /** - */ public function testUnmarshalling(): void { - /** @var \Dom\Element $xml */ $xml = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $xml); + $chunk = new Chunk($xml); $this->assertEquals($chunk->getLocalName(), 'Element'); diff --git a/tests/XML/DOMDocumentFactoryTest.php b/tests/XML/DOMDocumentFactoryTest.php index ac899727..21e5bddf 100644 --- a/tests/XML/DOMDocumentFactoryTest.php +++ b/tests/XML/DOMDocumentFactoryTest.php @@ -112,6 +112,8 @@ public function testEmptyStringIsNotValid(): void $this->expectExceptionMessage( 'Expected a non-whitespace string. Got: ""', ); + + /** @phpstan-ignore-next-line argument.type */ DOMDocumentFactory::fromString(''); } @@ -122,9 +124,15 @@ public function testNormalizeDocument(): void $notNormalized = DOMDocumentFactory::fromFile('tests/resources/xml/domdocument_not_normalized.xml'); $normalizedDoc = DOMDocumentFactory::normalizeDocument($notNormalized); + $normalizedRoot = $normalized->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $normalizedRoot); + + $normalizedDocRoot = $normalizedDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $normalizedDocRoot); + $this->assertSame( - $normalized->documentElement->C14N(), - $normalizedDoc->documentElement->C14N(), + $normalizedRoot->C14N(), + $normalizedDocRoot->C14N(), ); } } diff --git a/tests/XML/ExtendableAttributesTest.php b/tests/XML/ExtendableAttributesTest.php index 1aa14ee2..973dd7e2 100644 --- a/tests/XML/ExtendableAttributesTest.php +++ b/tests/XML/ExtendableAttributesTest.php @@ -27,8 +27,6 @@ final class ExtendableAttributesTest extends TestCase use SerializableElementTestTrait; - /** - */ public static function setUpBeforeClass(): void { self::$testedClass = ExtendableAttributesElement::class; @@ -39,8 +37,6 @@ public static function setUpBeforeClass(): void } - /** - */ public function testMarshalling(): void { $extendableElement = new ExtendableAttributesElement( @@ -50,21 +46,33 @@ public function testMarshalling(): void ], ); - $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $representationRoot = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $representationRoot); + + $expectedXml = self::$xmlRepresentation->saveXml($representationRoot); + $this->assertNotSame('', $expectedXml); + /** @var non-empty-string $expectedXml */ + $actualXml = strval($extendableElement); + $this->assertNotSame('', $actualXml); + /** @var non-empty-string $actualXml */ $expectedDoc = DOMDocumentFactory::fromString($expectedXml); $actualDoc = DOMDocumentFactory::fromString($actualXml); + $expectedRoot = $expectedDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $expectedRoot); + + $actualRoot = $actualDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $actualRoot); + $this->assertEquals( - $expectedDoc->documentElement->C14N(), - $actualDoc->documentElement->C14N(), + $expectedRoot->C14N(), + $actualRoot->C14N(), ); } - /** - */ public function testMarshallingWithExcludedAttribute(): void { $this->expectException(InvalidDOMAttributeException::class); @@ -78,12 +86,10 @@ public function testMarshallingWithExcludedAttribute(): void } - /** - */ public function testGetAttributesNSFromXML(): void { - /** @var \Dom\Element $element */ $element = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $element); $elt = ExtendableAttributesElement::fromXML($element); $attributes = $elt->getAttributesNS(); diff --git a/tests/XML/ExtendableElementTest.php b/tests/XML/ExtendableElementTest.php index a8a024f2..4e52e08b 100644 --- a/tests/XML/ExtendableElementTest.php +++ b/tests/XML/ExtendableElementTest.php @@ -26,20 +26,15 @@ final class ExtendableElementTest extends TestCase use SerializableElementTestTrait; - /** - */ public static function setUpBeforeClass(): void { self::$testedClass = ExtendableElement::class; - self::$xmlRepresentation = DOMDocumentFactory::fromFile( - dirname(__FILE__, 2) . '/resources/xml/ssp_ExtendableElement.xml', - ); + $fixturePath = dirname(__FILE__, 2) . '/resources/xml/ssp_ExtendableElement.xml'; + self::$xmlRepresentation = DOMDocumentFactory::fromFile($fixturePath); } - /** - */ public function testMarshalling(): void { $dummyDocument1 = DOMDocumentFactory::fromString( @@ -49,10 +44,11 @@ public function testMarshalling(): void 'some', ); - /** @var \Dom\Element $dummyElement1 */ $dummyElement1 = $dummyDocument1->documentElement; - /** @var \Dom\Element $dummyElement2 */ + $this->assertInstanceOf(\Dom\Element::class, $dummyElement1); + $dummyElement2 = $dummyDocument2->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $dummyElement2); $extendableElement = new ExtendableElement( [ @@ -61,21 +57,33 @@ public function testMarshalling(): void ], ); - $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $representationRoot = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $representationRoot); + + $expectedXml = self::$xmlRepresentation->saveXml($representationRoot); + $this->assertNotSame('', $expectedXml); + /** @var non-empty-string $expectedXml */ + $actualXml = strval($extendableElement); + $this->assertNotSame('', $actualXml); + /** @var non-empty-string $actualXml */ $expectedDoc = DOMDocumentFactory::fromString($expectedXml); $actualDoc = DOMDocumentFactory::fromString($actualXml); + $expectedRoot = $expectedDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $expectedRoot); + + $actualRoot = $actualDoc->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $actualRoot); + $this->assertEquals( - $expectedDoc->documentElement->C14N(), - $actualDoc->documentElement->C14N(), + $expectedRoot->C14N(), + $actualRoot->C14N(), ); } - /** - */ public function testMarshallingWithExcludedElement(): void { $dummyDocument1 = DOMDocumentFactory::fromString( @@ -88,12 +96,14 @@ public function testMarshallingWithExcludedElement(): void 'some', ); - /** @var \Dom\Element $dummyElement1 */ $dummyElement1 = $dummyDocument1->documentElement; - /** @var \Dom\Element $dummyElement2 */ + $this->assertInstanceOf(\Dom\Element::class, $dummyElement1); + $dummyElement2 = $dummyDocument2->documentElement; - /** @var \Dom\Element $dummyElement3 */ + $this->assertInstanceOf(\Dom\Element::class, $dummyElement2); + $dummyElement3 = $dummyDocument3->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $dummyElement3); $this->expectException(InvalidDOMElementException::class); new ExtendableElement( @@ -106,12 +116,10 @@ public function testMarshallingWithExcludedElement(): void } - /** - */ public function testGetChildElementsFromXML(): void { - /** @var \Dom\Element $element */ $element = self::$xmlRepresentation->documentElement; + $this->assertInstanceOf(\Dom\Element::class, $element); $elt = ExtendableElement::fromXML($element); /** @var \SimpleSAML\XML\Chunk[] $elements */ diff --git a/tests/XPath/XPathTest.php b/tests/XPath/XPathTest.php index f88a1f6f..008815fb 100644 --- a/tests/XPath/XPathTest.php +++ b/tests/XPath/XPathTest.php @@ -323,6 +323,8 @@ public static function xmlVariantsProviderForTopLevelSlatePerson(): array * Ensure that absolute XPath '/foo:serviceResponse/foo:authenticationSuccess/slate:person' * finds the same top-level slate:person regardless of whether it appears before or after * cas:attributes in the document, even when the slate prefix is only declared on the element itself. + * + * @param non-empty-string $filePath */ #[DataProvider('xmlVariantsProviderForTopLevelSlatePerson')] public function testAbsoluteXPathFindsTopLevelSlatePerson( diff --git a/tools/composer-require-checker.json b/tools/composer-require-checker.json index 65a11202..a1b57633 100644 --- a/tools/composer-require-checker.json +++ b/tools/composer-require-checker.json @@ -1,6 +1,7 @@ { - "symbol-whitelist": [ - "LIBXML_NO_XXE", - "PHPUnit\\Framework\\Attributes\\Depends" - ] + "symbol-whitelist": [ + "LIBXML_NO_XXE", + "PHPUnit\\Framework\\Attributes\\Depends", + "PHPUnit\\Framework\\Assert" + ] } From b93a3de6b511969a101d5cf326ecc54eef85165c Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sat, 30 May 2026 13:08:44 +0000 Subject: [PATCH 3/4] use assertXmlStringEqualsXmlString to compare xml strings --- tests/XMLSchema/XML/AllTest.php | 9 +++++---- tests/XMLSchema/XML/AnnotationTest.php | 9 +++++---- tests/XMLSchema/XML/AnyAttributeTest.php | 9 +++++---- tests/XMLSchema/XML/AnyTest.php | 9 +++++---- tests/XMLSchema/XML/AppinfoTest.php | 9 +++++---- tests/XMLSchema/XML/ChoiceTest.php | 9 +++++---- tests/XMLSchema/XML/ComplexContentTest.php | 9 +++++---- tests/XMLSchema/XML/ComplexRestrictionTest.php | 9 +++++---- tests/XMLSchema/XML/DocumentationTest.php | 9 +++++---- tests/XMLSchema/XML/EnumerationTest.php | 9 +++++---- tests/XMLSchema/XML/ExtensionTest.php | 9 +++++---- tests/XMLSchema/XML/FieldTest.php | 9 +++++---- tests/XMLSchema/XML/FractionDigitsTest.php | 9 +++++---- tests/XMLSchema/XML/ImportTest.php | 9 +++++---- tests/XMLSchema/XML/IncludeTest.php | 9 +++++---- tests/XMLSchema/XML/KeyTest.php | 9 +++++---- tests/XMLSchema/XML/KeyrefTest.php | 9 +++++---- tests/XMLSchema/XML/LengthTest.php | 9 +++++---- tests/XMLSchema/XML/ListTest.php | 9 +++++---- tests/XMLSchema/XML/LocalAttributeTest.php | 9 +++++---- tests/XMLSchema/XML/LocalComplexTypeTest.php | 9 +++++---- tests/XMLSchema/XML/LocalElementTest.php | 9 +++++---- tests/XMLSchema/XML/LocalSimpleTypeTest.php | 9 +++++---- tests/XMLSchema/XML/MaxExclusiveTest.php | 9 +++++---- tests/XMLSchema/XML/MaxInclusiveTest.php | 9 +++++---- tests/XMLSchema/XML/MaxLengthTest.php | 9 +++++---- tests/XMLSchema/XML/MinExclusiveTest.php | 9 +++++---- tests/XMLSchema/XML/MinInclusiveTest.php | 9 +++++---- tests/XMLSchema/XML/MinLengthTest.php | 9 +++++---- tests/XMLSchema/XML/NamedAttributeGroupTest.php | 9 +++++---- tests/XMLSchema/XML/NamedGroupTest.php | 9 +++++---- tests/XMLSchema/XML/NarrowMaxMinElementTest.php | 9 +++++---- tests/XMLSchema/XML/NotationTest.php | 9 +++++---- tests/XMLSchema/XML/PatternTest.php | 9 +++++---- tests/XMLSchema/XML/RedefineTest.php | 9 +++++---- tests/XMLSchema/XML/ReferencedAttributeGroupTest.php | 9 +++++---- tests/XMLSchema/XML/ReferencedGroupTest.php | 9 +++++---- tests/XMLSchema/XML/RestrictionTest.php | 9 +++++---- tests/XMLSchema/XML/SchemaTest.php | 9 +++++---- tests/XMLSchema/XML/SelectorTest.php | 9 +++++---- tests/XMLSchema/XML/SequenceTest.php | 9 +++++---- tests/XMLSchema/XML/SimpleChoiceTest.php | 9 +++++---- tests/XMLSchema/XML/SimpleContentTest.php | 9 +++++---- tests/XMLSchema/XML/SimpleExtensionTest.php | 9 +++++---- tests/XMLSchema/XML/SimpleRestrictionTest.php | 9 +++++---- tests/XMLSchema/XML/SimpleSequenceTest.php | 9 +++++---- tests/XMLSchema/XML/TopLevelAttributeTest.php | 9 +++++---- tests/XMLSchema/XML/TopLevelComplexTypeTest.php | 9 +++++---- tests/XMLSchema/XML/TopLevelElementTest.php | 9 +++++---- tests/XMLSchema/XML/TopLevelSimpleTypeTest.php | 9 +++++---- tests/XMLSchema/XML/TotalDigitsTest.php | 9 +++++---- tests/XMLSchema/XML/UnionTest.php | 9 +++++---- tests/XMLSchema/XML/UniqueTest.php | 11 ++++++----- tests/XMLSchema/XML/WhiteSpaceTest.php | 9 +++++---- 54 files changed, 271 insertions(+), 217 deletions(-) diff --git a/tests/XMLSchema/XML/AllTest.php b/tests/XMLSchema/XML/AllTest.php index 43c0211f..25aeb63b 100644 --- a/tests/XMLSchema/XML/AllTest.php +++ b/tests/XMLSchema/XML/AllTest.php @@ -223,10 +223,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($all), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($all); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($all->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/AnnotationTest.php b/tests/XMLSchema/XML/AnnotationTest.php index 930d565c..2dc81410 100644 --- a/tests/XMLSchema/XML/AnnotationTest.php +++ b/tests/XMLSchema/XML/AnnotationTest.php @@ -88,10 +88,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($annotation), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($annotation); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($annotation->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/AnyAttributeTest.php b/tests/XMLSchema/XML/AnyAttributeTest.php index 03e61265..29c836ce 100644 --- a/tests/XMLSchema/XML/AnyAttributeTest.php +++ b/tests/XMLSchema/XML/AnyAttributeTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($anyAttribute), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($anyAttribute); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/AnyTest.php b/tests/XMLSchema/XML/AnyTest.php index 53d986b7..3d39cb47 100644 --- a/tests/XMLSchema/XML/AnyTest.php +++ b/tests/XMLSchema/XML/AnyTest.php @@ -109,10 +109,11 @@ public function testMarshalling(): void MaxOccursValue::fromString('unbounded'), ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($any), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($any); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } diff --git a/tests/XMLSchema/XML/AppinfoTest.php b/tests/XMLSchema/XML/AppinfoTest.php index a93bf483..809b46ef 100644 --- a/tests/XMLSchema/XML/AppinfoTest.php +++ b/tests/XMLSchema/XML/AppinfoTest.php @@ -56,10 +56,11 @@ public function testMarshalling(): void { $appinfo = self::$testContainer->getAppinfo(1); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($appinfo), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($appinfo); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($appinfo->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/ChoiceTest.php b/tests/XMLSchema/XML/ChoiceTest.php index 662ea11b..19647b8d 100644 --- a/tests/XMLSchema/XML/ChoiceTest.php +++ b/tests/XMLSchema/XML/ChoiceTest.php @@ -109,10 +109,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($choice), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($choice); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } diff --git a/tests/XMLSchema/XML/ComplexContentTest.php b/tests/XMLSchema/XML/ComplexContentTest.php index d1c0be6d..7d74a994 100644 --- a/tests/XMLSchema/XML/ComplexContentTest.php +++ b/tests/XMLSchema/XML/ComplexContentTest.php @@ -142,10 +142,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($complexContent), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($complexContent); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($complexContent->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/ComplexRestrictionTest.php b/tests/XMLSchema/XML/ComplexRestrictionTest.php index 2b1332a7..2e5e30c1 100644 --- a/tests/XMLSchema/XML/ComplexRestrictionTest.php +++ b/tests/XMLSchema/XML/ComplexRestrictionTest.php @@ -134,9 +134,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($complexRestriction), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($complexRestriction); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/DocumentationTest.php b/tests/XMLSchema/XML/DocumentationTest.php index 4f696281..69107fbd 100644 --- a/tests/XMLSchema/XML/DocumentationTest.php +++ b/tests/XMLSchema/XML/DocumentationTest.php @@ -66,10 +66,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(1)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($documentation), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($documentation); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($documentation->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/EnumerationTest.php b/tests/XMLSchema/XML/EnumerationTest.php index cc769cd1..61a6e38e 100644 --- a/tests/XMLSchema/XML/EnumerationTest.php +++ b/tests/XMLSchema/XML/EnumerationTest.php @@ -100,9 +100,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($enumeration), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($enumeration); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/ExtensionTest.php b/tests/XMLSchema/XML/ExtensionTest.php index 911990d5..975faff9 100644 --- a/tests/XMLSchema/XML/ExtensionTest.php +++ b/tests/XMLSchema/XML/ExtensionTest.php @@ -132,9 +132,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($extension), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($extension); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/FieldTest.php b/tests/XMLSchema/XML/FieldTest.php index 4193a2e5..2ffde5b4 100644 --- a/tests/XMLSchema/XML/FieldTest.php +++ b/tests/XMLSchema/XML/FieldTest.php @@ -98,9 +98,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($field), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($field); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/FractionDigitsTest.php b/tests/XMLSchema/XML/FractionDigitsTest.php index 12fbd9b3..e442e5c5 100644 --- a/tests/XMLSchema/XML/FractionDigitsTest.php +++ b/tests/XMLSchema/XML/FractionDigitsTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($fractionDigits), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($fractionDigits); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/ImportTest.php b/tests/XMLSchema/XML/ImportTest.php index 2afcc00c..bf1e8acf 100644 --- a/tests/XMLSchema/XML/ImportTest.php +++ b/tests/XMLSchema/XML/ImportTest.php @@ -98,9 +98,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($import), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($import); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/IncludeTest.php b/tests/XMLSchema/XML/IncludeTest.php index 86066bf0..1ad3c548 100644 --- a/tests/XMLSchema/XML/IncludeTest.php +++ b/tests/XMLSchema/XML/IncludeTest.php @@ -97,9 +97,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($include), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($include); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/KeyTest.php b/tests/XMLSchema/XML/KeyTest.php index 31f0fb03..0291c803 100644 --- a/tests/XMLSchema/XML/KeyTest.php +++ b/tests/XMLSchema/XML/KeyTest.php @@ -132,10 +132,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($key), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($key); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($key->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/KeyrefTest.php b/tests/XMLSchema/XML/KeyrefTest.php index ee77497d..5f845079 100644 --- a/tests/XMLSchema/XML/KeyrefTest.php +++ b/tests/XMLSchema/XML/KeyrefTest.php @@ -134,10 +134,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($keyref), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($keyref); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($keyref->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/LengthTest.php b/tests/XMLSchema/XML/LengthTest.php index 35365b01..3553e48c 100644 --- a/tests/XMLSchema/XML/LengthTest.php +++ b/tests/XMLSchema/XML/LengthTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($length), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($length); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/ListTest.php b/tests/XMLSchema/XML/ListTest.php index 942d7976..f3e9cb90 100644 --- a/tests/XMLSchema/XML/ListTest.php +++ b/tests/XMLSchema/XML/ListTest.php @@ -99,9 +99,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($xsList), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($xsList); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/LocalAttributeTest.php b/tests/XMLSchema/XML/LocalAttributeTest.php index d2a47c77..0252eefe 100644 --- a/tests/XMLSchema/XML/LocalAttributeTest.php +++ b/tests/XMLSchema/XML/LocalAttributeTest.php @@ -126,9 +126,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($attribute), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($attribute); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/LocalComplexTypeTest.php b/tests/XMLSchema/XML/LocalComplexTypeTest.php index e2cb46b3..0e9c4cb8 100644 --- a/tests/XMLSchema/XML/LocalComplexTypeTest.php +++ b/tests/XMLSchema/XML/LocalComplexTypeTest.php @@ -136,10 +136,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($localComplexType), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($localComplexType); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($localComplexType->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/LocalElementTest.php b/tests/XMLSchema/XML/LocalElementTest.php index 4c84a333..7dcedf4a 100644 --- a/tests/XMLSchema/XML/LocalElementTest.php +++ b/tests/XMLSchema/XML/LocalElementTest.php @@ -159,10 +159,11 @@ public function testMarshalling(): void namespacedAttributes: [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($localElement), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($localElement); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($localElement->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/LocalSimpleTypeTest.php b/tests/XMLSchema/XML/LocalSimpleTypeTest.php index 943728e9..2ce98849 100644 --- a/tests/XMLSchema/XML/LocalSimpleTypeTest.php +++ b/tests/XMLSchema/XML/LocalSimpleTypeTest.php @@ -107,10 +107,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($localSimpleType), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($localSimpleType); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($localSimpleType->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/MaxExclusiveTest.php b/tests/XMLSchema/XML/MaxExclusiveTest.php index 61062dfa..109c9015 100644 --- a/tests/XMLSchema/XML/MaxExclusiveTest.php +++ b/tests/XMLSchema/XML/MaxExclusiveTest.php @@ -102,9 +102,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($maxExclusive), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($maxExclusive); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/MaxInclusiveTest.php b/tests/XMLSchema/XML/MaxInclusiveTest.php index c84f36e1..a178394c 100644 --- a/tests/XMLSchema/XML/MaxInclusiveTest.php +++ b/tests/XMLSchema/XML/MaxInclusiveTest.php @@ -102,9 +102,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($maxInclusive), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($maxInclusive); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/MaxLengthTest.php b/tests/XMLSchema/XML/MaxLengthTest.php index 86a864dc..de5f61f5 100644 --- a/tests/XMLSchema/XML/MaxLengthTest.php +++ b/tests/XMLSchema/XML/MaxLengthTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($MaxLength), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($MaxLength); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/MinExclusiveTest.php b/tests/XMLSchema/XML/MinExclusiveTest.php index bc95f274..36de44d5 100644 --- a/tests/XMLSchema/XML/MinExclusiveTest.php +++ b/tests/XMLSchema/XML/MinExclusiveTest.php @@ -102,9 +102,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($minExclusive), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($minExclusive); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/MinInclusiveTest.php b/tests/XMLSchema/XML/MinInclusiveTest.php index 9c2b2dea..78a1fd0a 100644 --- a/tests/XMLSchema/XML/MinInclusiveTest.php +++ b/tests/XMLSchema/XML/MinInclusiveTest.php @@ -102,9 +102,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($minInclusive), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($minInclusive); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/MinLengthTest.php b/tests/XMLSchema/XML/MinLengthTest.php index d200c4a1..4babb93d 100644 --- a/tests/XMLSchema/XML/MinLengthTest.php +++ b/tests/XMLSchema/XML/MinLengthTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($minLength), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($minLength); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/NamedAttributeGroupTest.php b/tests/XMLSchema/XML/NamedAttributeGroupTest.php index 7c76ceff..1b6f78dc 100644 --- a/tests/XMLSchema/XML/NamedAttributeGroupTest.php +++ b/tests/XMLSchema/XML/NamedAttributeGroupTest.php @@ -127,10 +127,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($attributeGroup), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($attributeGroup); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($attributeGroup->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/NamedGroupTest.php b/tests/XMLSchema/XML/NamedGroupTest.php index 52c8ca9e..97c79218 100644 --- a/tests/XMLSchema/XML/NamedGroupTest.php +++ b/tests/XMLSchema/XML/NamedGroupTest.php @@ -173,9 +173,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($namedGroup), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($namedGroup); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/NarrowMaxMinElementTest.php b/tests/XMLSchema/XML/NarrowMaxMinElementTest.php index 844d3137..05ef69c3 100644 --- a/tests/XMLSchema/XML/NarrowMaxMinElementTest.php +++ b/tests/XMLSchema/XML/NarrowMaxMinElementTest.php @@ -161,9 +161,10 @@ public function testMarshalling(): void namespacedAttributes: [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($narrowMaxMinElement), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($narrowMaxMinElement); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/NotationTest.php b/tests/XMLSchema/XML/NotationTest.php index 2a5b9037..15f57a0a 100644 --- a/tests/XMLSchema/XML/NotationTest.php +++ b/tests/XMLSchema/XML/NotationTest.php @@ -101,9 +101,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($notation), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($notation); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/PatternTest.php b/tests/XMLSchema/XML/PatternTest.php index 64b6c92d..f6adda34 100644 --- a/tests/XMLSchema/XML/PatternTest.php +++ b/tests/XMLSchema/XML/PatternTest.php @@ -100,9 +100,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($pattern), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($pattern); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/RedefineTest.php b/tests/XMLSchema/XML/RedefineTest.php index 0e6962c0..cef41bd7 100644 --- a/tests/XMLSchema/XML/RedefineTest.php +++ b/tests/XMLSchema/XML/RedefineTest.php @@ -309,10 +309,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($redefine), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($redefine); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($redefine->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/ReferencedAttributeGroupTest.php b/tests/XMLSchema/XML/ReferencedAttributeGroupTest.php index f8201445..3647e098 100644 --- a/tests/XMLSchema/XML/ReferencedAttributeGroupTest.php +++ b/tests/XMLSchema/XML/ReferencedAttributeGroupTest.php @@ -100,10 +100,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($attributeGroup), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($attributeGroup); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($attributeGroup->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/ReferencedGroupTest.php b/tests/XMLSchema/XML/ReferencedGroupTest.php index 491311c9..04ee8d5a 100644 --- a/tests/XMLSchema/XML/ReferencedGroupTest.php +++ b/tests/XMLSchema/XML/ReferencedGroupTest.php @@ -102,9 +102,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($referencedGroup), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($referencedGroup); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/RestrictionTest.php b/tests/XMLSchema/XML/RestrictionTest.php index 0cffaef8..cd0ff509 100644 --- a/tests/XMLSchema/XML/RestrictionTest.php +++ b/tests/XMLSchema/XML/RestrictionTest.php @@ -106,9 +106,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($restriction), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($restriction); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/SchemaTest.php b/tests/XMLSchema/XML/SchemaTest.php index f8016c68..cc49a3e7 100644 --- a/tests/XMLSchema/XML/SchemaTest.php +++ b/tests/XMLSchema/XML/SchemaTest.php @@ -224,10 +224,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($schema), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($schema); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($schema->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/SelectorTest.php b/tests/XMLSchema/XML/SelectorTest.php index 29123abc..7212be35 100644 --- a/tests/XMLSchema/XML/SelectorTest.php +++ b/tests/XMLSchema/XML/SelectorTest.php @@ -98,9 +98,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($selector), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($selector); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/SequenceTest.php b/tests/XMLSchema/XML/SequenceTest.php index d595ae94..c7660b65 100644 --- a/tests/XMLSchema/XML/SequenceTest.php +++ b/tests/XMLSchema/XML/SequenceTest.php @@ -109,9 +109,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($sequence), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($sequence); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/SimpleChoiceTest.php b/tests/XMLSchema/XML/SimpleChoiceTest.php index 7c7c2a22..3b08e854 100644 --- a/tests/XMLSchema/XML/SimpleChoiceTest.php +++ b/tests/XMLSchema/XML/SimpleChoiceTest.php @@ -107,10 +107,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($choice), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($choice); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } diff --git a/tests/XMLSchema/XML/SimpleContentTest.php b/tests/XMLSchema/XML/SimpleContentTest.php index b7b8c96c..e12967f3 100644 --- a/tests/XMLSchema/XML/SimpleContentTest.php +++ b/tests/XMLSchema/XML/SimpleContentTest.php @@ -131,10 +131,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($simpleContent), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($simpleContent); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($simpleContent->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/SimpleExtensionTest.php b/tests/XMLSchema/XML/SimpleExtensionTest.php index b1c147b3..00904f34 100644 --- a/tests/XMLSchema/XML/SimpleExtensionTest.php +++ b/tests/XMLSchema/XML/SimpleExtensionTest.php @@ -125,9 +125,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($simpleExtension), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($simpleExtension); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/SimpleRestrictionTest.php b/tests/XMLSchema/XML/SimpleRestrictionTest.php index a3cd40fa..d904267e 100644 --- a/tests/XMLSchema/XML/SimpleRestrictionTest.php +++ b/tests/XMLSchema/XML/SimpleRestrictionTest.php @@ -245,9 +245,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($simpleRestriction), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($simpleRestriction); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/SimpleSequenceTest.php b/tests/XMLSchema/XML/SimpleSequenceTest.php index 9a7074e0..cbaf74b2 100644 --- a/tests/XMLSchema/XML/SimpleSequenceTest.php +++ b/tests/XMLSchema/XML/SimpleSequenceTest.php @@ -107,9 +107,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($sequence), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($sequence); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/TopLevelAttributeTest.php b/tests/XMLSchema/XML/TopLevelAttributeTest.php index ceaeac1e..91651bf6 100644 --- a/tests/XMLSchema/XML/TopLevelAttributeTest.php +++ b/tests/XMLSchema/XML/TopLevelAttributeTest.php @@ -123,9 +123,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($attribute), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($attribute); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/TopLevelComplexTypeTest.php b/tests/XMLSchema/XML/TopLevelComplexTypeTest.php index 2769ce4e..08f98e9c 100644 --- a/tests/XMLSchema/XML/TopLevelComplexTypeTest.php +++ b/tests/XMLSchema/XML/TopLevelComplexTypeTest.php @@ -144,10 +144,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($topLevelComplexType), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($topLevelComplexType); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($topLevelComplexType->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/TopLevelElementTest.php b/tests/XMLSchema/XML/TopLevelElementTest.php index da5a6170..47ea62d8 100644 --- a/tests/XMLSchema/XML/TopLevelElementTest.php +++ b/tests/XMLSchema/XML/TopLevelElementTest.php @@ -156,10 +156,11 @@ public function testMarshalling(): void namespacedAttributes: [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($topLevelElement), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($topLevelElement); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($topLevelElement->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/TopLevelSimpleTypeTest.php b/tests/XMLSchema/XML/TopLevelSimpleTypeTest.php index 26f68d09..44bce8ca 100644 --- a/tests/XMLSchema/XML/TopLevelSimpleTypeTest.php +++ b/tests/XMLSchema/XML/TopLevelSimpleTypeTest.php @@ -124,10 +124,11 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($topLevelSimpleType), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($topLevelSimpleType); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($topLevelSimpleType->isEmptyElement()); } diff --git a/tests/XMLSchema/XML/TotalDigitsTest.php b/tests/XMLSchema/XML/TotalDigitsTest.php index 4987dd89..0d774f6e 100644 --- a/tests/XMLSchema/XML/TotalDigitsTest.php +++ b/tests/XMLSchema/XML/TotalDigitsTest.php @@ -104,9 +104,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($totalDigits), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($totalDigits); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/UnionTest.php b/tests/XMLSchema/XML/UnionTest.php index a79090a4..f1620130 100644 --- a/tests/XMLSchema/XML/UnionTest.php +++ b/tests/XMLSchema/XML/UnionTest.php @@ -126,9 +126,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($union), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($union); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/UniqueTest.php b/tests/XMLSchema/XML/UniqueTest.php index 5f61f187..a6a482a0 100644 --- a/tests/XMLSchema/XML/UniqueTest.php +++ b/tests/XMLSchema/XML/UniqueTest.php @@ -132,11 +132,12 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(3)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($unique), - ); - $this->assertFalse($unique->isEmptyElement()); + + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($unique); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/XMLSchema/XML/WhiteSpaceTest.php b/tests/XMLSchema/XML/WhiteSpaceTest.php index 16a68eec..64fbcef3 100644 --- a/tests/XMLSchema/XML/WhiteSpaceTest.php +++ b/tests/XMLSchema/XML/WhiteSpaceTest.php @@ -103,9 +103,10 @@ public function testMarshalling(): void [self::$testContainer->getXMLAttribute(4)], ); - $this->assertEquals( - self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement), - strval($whiteSpace), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($whiteSpace); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } From af10c61536a3559d07fc01fcf50d7c00caa93d50 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sat, 30 May 2026 13:45:59 +0000 Subject: [PATCH 4/4] use C::NS_XMLNS constant instead of the actual XMLNS namespace URI --- src/XML/ExtendableAttributesTrait.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/XML/ExtendableAttributesTrait.php b/src/XML/ExtendableAttributesTrait.php index 4c237aec..0b8cdefe 100644 --- a/src/XML/ExtendableAttributesTrait.php +++ b/src/XML/ExtendableAttributesTrait.php @@ -7,7 +7,6 @@ use Dom; use RuntimeException; use SimpleSAML\XML\Assert\Assert; -use SimpleSAML\XML\Attribute; use SimpleSAML\XML\Constants as C; use SimpleSAML\XMLSchema\Exception\InvalidDOMAttributeException; use SimpleSAML\XMLSchema\Exception\SchemaViolationException; @@ -109,7 +108,7 @@ protected static function getAttributesNSFromXML( Assert::oneOf($namespace, NS::$PREDEFINED); foreach ($xml->attributes as $a) { - if ($a->namespaceURI === 'http://www.w3.org/2000/xmlns/') { + if ($a->namespaceURI === C::NS_XMLNS) { continue; } @@ -152,7 +151,7 @@ protected static function getAttributesNSFromXML( } foreach ($xml->attributes as $a) { - if ($a->namespaceURI === 'http://www.w3.org/2000/xmlns/') { + if ($a->namespaceURI === C::NS_XMLNS) { continue; }