From 1245a99bc60c510085d5b5a185a96ffb7d5ac942 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 10 Jun 2026 22:06:31 +0200 Subject: [PATCH] Migrate DOM-classes to PHP 8.4's new DOM-API --- composer.json | 4 ++-- src/Utils/XPath.php | 11 ++++----- src/XML/wsx/GetMetadata.php | 6 ++--- src/XML/wsx/Metadata.php | 6 ++--- src/XML/wsx/MetadataReference.php | 6 ++--- src/XML/wsx/MetadataSection.php | 6 ++--- .../MetadataExchange/XML/wsx/DialectTest.php | 9 ++++---- .../XML/wsx/GetMetadataTest.php | 9 ++++---- .../XML/wsx/IdentifierTest.php | 9 ++++---- .../MetadataExchange/XML/wsx/LocationTest.php | 9 ++++---- .../XML/wsx/MetadataReferenceTest.php | 23 ++++++++++--------- .../XML/wsx/MetadataSectionTest.php | 9 ++++---- .../MetadataExchange/XML/wsx/MetadataTest.php | 9 ++++---- 13 files changed, 61 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index 71ee8fd..8c51191 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ "ext-dom": "*", "simplesamlphp/assert": "~2.0", - "simplesamlphp/xml-common": "~2.8" + "simplesamlphp/xml-common": "dev-feature/dom-migration-php84" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "~1.11", - "simplesamlphp/xml-ws-addressing": "~1.3" + "simplesamlphp/xml-ws-addressing": "dev-feature/dom-migration-php84" }, "autoload": { "psr-4": { diff --git a/src/Utils/XPath.php b/src/Utils/XPath.php index 1d48767..985ffd0 100644 --- a/src/Utils/XPath.php +++ b/src/Utils/XPath.php @@ -4,8 +4,7 @@ namespace SimpleSAML\WebServices\MetadataExchange\Utils; -use DOMNode; -use DOMXPath; +use Dom; use SimpleSAML\WebServices\MetadataExchange\Constants as C; /** @@ -16,15 +15,15 @@ class XPath extends \SimpleSAML\XPath\XPath { /* - * Get a DOMXPath object that can be used to search for WS Metadata Exchange elements. + * Get a Dom\XPath object that can be used to search for WS Metadata Exchange elements. * - * @param \DOMNode $node The document to associate to the DOMXPath object. + * @param \Dom\Node $node The document to associate to the Dom\XPath object. * @param bool $autoregister Whether to auto-register all namespaces used in the document * - * @return \DOMXPath A DOMXPath object ready to use in the given document, with several + * @return \Dom\XPath A Dom\XPath object ready to use in the given document, with several * ws-related namespaces already registered. */ - public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath + public static function getXPath(Dom\Node $node, bool $autoregister = false): Dom\XPath { $xp = parent::getXPath($node, $autoregister); diff --git a/src/XML/wsx/GetMetadata.php b/src/XML/wsx/GetMetadata.php index 874ea2b..dd1a207 100644 --- a/src/XML/wsx/GetMetadata.php +++ b/src/XML/wsx/GetMetadata.php @@ -4,7 +4,7 @@ namespace SimpleSAML\WebServices\MetadataExchange\XML\wsx; -use DOMElement; +use Dom; use SimpleSAML\WebServices\MetadataExchange\Assert\Assert; use SimpleSAML\XML\ExtendableAttributesTrait; use SimpleSAML\XML\SchemaValidatableElementInterface; @@ -85,7 +85,7 @@ public function isEmptyElement(): bool * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException * if the qualified name of the supplied element is wrong */ - public static function fromXML(DOMElement $xml): static + public static function fromXML(Dom\Element $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); @@ -107,7 +107,7 @@ public static function fromXML(DOMElement $xml): static /** * Add this GetMetadata to an XML element. */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = parent::instantiateParentElement($parent); diff --git a/src/XML/wsx/Metadata.php b/src/XML/wsx/Metadata.php index 5b0cbba..08a12ad 100644 --- a/src/XML/wsx/Metadata.php +++ b/src/XML/wsx/Metadata.php @@ -4,7 +4,7 @@ namespace SimpleSAML\WebServices\MetadataExchange\XML\wsx; -use DOMElement; +use Dom; use SimpleSAML\WebServices\MetadataExchange\Assert\Assert; use SimpleSAML\XML\ExtendableAttributesTrait; use SimpleSAML\XML\ExtendableElementTrait; @@ -77,7 +77,7 @@ public function isEmptyElement(): bool * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException * if the qualified name of the supplied element is wrong */ - public static function fromXML(DOMElement $xml): static + public static function fromXML(Dom\Element $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); @@ -93,7 +93,7 @@ public static function fromXML(DOMElement $xml): static /** * Add this Metadata to an XML element. */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = parent::instantiateParentElement($parent); diff --git a/src/XML/wsx/MetadataReference.php b/src/XML/wsx/MetadataReference.php index 5587dfa..0844a76 100644 --- a/src/XML/wsx/MetadataReference.php +++ b/src/XML/wsx/MetadataReference.php @@ -4,7 +4,7 @@ namespace SimpleSAML\WebServices\MetadataExchange\XML\wsx; -use DOMElement; +use Dom; use SimpleSAML\WebServices\MetadataExchange\Assert\Assert; use SimpleSAML\XML\ExtendableElementTrait; use SimpleSAML\XML\SchemaValidatableElementInterface; @@ -47,7 +47,7 @@ final public function __construct( * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException * if the qualified name of the supplied element is wrong */ - public static function fromXML(DOMElement $xml): static + public static function fromXML(Dom\Element $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); @@ -61,7 +61,7 @@ public static function fromXML(DOMElement $xml): static /** * Add this MetadataReference to an XML element. */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = parent::instantiateParentElement($parent); diff --git a/src/XML/wsx/MetadataSection.php b/src/XML/wsx/MetadataSection.php index 0d1ebb8..735301a 100644 --- a/src/XML/wsx/MetadataSection.php +++ b/src/XML/wsx/MetadataSection.php @@ -4,7 +4,7 @@ namespace SimpleSAML\WebServices\MetadataExchange\XML\wsx; -use DOMElement; +use Dom; use SimpleSAML\WebServices\MetadataExchange\Assert\Assert; use SimpleSAML\XML\ExtendableAttributesTrait; use SimpleSAML\XML\ExtendableElementTrait; @@ -103,7 +103,7 @@ public function getIdentifier(): ?AnyURIValue * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException * if the qualified name of the supplied element is wrong */ - public static function fromXML(DOMElement $xml): static + public static function fromXML(Dom\Element $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); @@ -128,7 +128,7 @@ public static function fromXML(DOMElement $xml): static /** * Add this MetadataSection to an XML element. */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = parent::instantiateParentElement($parent); $e->setAttribute('Dialect', $this->getDialect()->getValue()); diff --git a/tests/MetadataExchange/XML/wsx/DialectTest.php b/tests/MetadataExchange/XML/wsx/DialectTest.php index 6176cb0..348e26f 100644 --- a/tests/MetadataExchange/XML/wsx/DialectTest.php +++ b/tests/MetadataExchange/XML/wsx/DialectTest.php @@ -52,9 +52,10 @@ public function testMarshalling(): void { $dialect = Dialect::fromString(C::NAMESPACE); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($dialect), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($dialect); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/MetadataExchange/XML/wsx/GetMetadataTest.php b/tests/MetadataExchange/XML/wsx/GetMetadataTest.php index 93b07a9..bd15967 100644 --- a/tests/MetadataExchange/XML/wsx/GetMetadataTest.php +++ b/tests/MetadataExchange/XML/wsx/GetMetadataTest.php @@ -62,10 +62,11 @@ public function testMarshalling(): void [$attr1], ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($getMetadata); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); $this->assertFalse($getMetadata->isEmptyElement()); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($getMetadata), - ); } } diff --git a/tests/MetadataExchange/XML/wsx/IdentifierTest.php b/tests/MetadataExchange/XML/wsx/IdentifierTest.php index d2a864c..d60e74a 100644 --- a/tests/MetadataExchange/XML/wsx/IdentifierTest.php +++ b/tests/MetadataExchange/XML/wsx/IdentifierTest.php @@ -52,9 +52,10 @@ public function testMarshalling(): void { $identifier = Identifier::fromString(C::NAMESPACE); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($identifier), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($identifier); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/MetadataExchange/XML/wsx/LocationTest.php b/tests/MetadataExchange/XML/wsx/LocationTest.php index ed30fad..b3f5333 100644 --- a/tests/MetadataExchange/XML/wsx/LocationTest.php +++ b/tests/MetadataExchange/XML/wsx/LocationTest.php @@ -52,9 +52,10 @@ public function testMarshalling(): void { $location = Location::fromString(C::NAMESPACE); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($location), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($location); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/MetadataExchange/XML/wsx/MetadataReferenceTest.php b/tests/MetadataExchange/XML/wsx/MetadataReferenceTest.php index a8e2087..56d4c1f 100644 --- a/tests/MetadataExchange/XML/wsx/MetadataReferenceTest.php +++ b/tests/MetadataExchange/XML/wsx/MetadataReferenceTest.php @@ -4,7 +4,7 @@ namespace SimpleSAML\Test\WebServices\MetadataExchange\XML\wsx; -use DOMElement; +use Dom; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; @@ -37,14 +37,14 @@ final class MetadataReferenceTest extends TestCase use SerializableElementTestTrait; - /** @var \DOMElement $referenceParametersContent */ - protected static DOMElement $referenceParametersContent; + /** @var \Dom\Element $referenceParametersContent */ + protected static Dom\Element $referenceParametersContent; - /** @var \DOMElement $metadataContent */ - protected static DOMElement $metadataContent; + /** @var \Dom\Element $metadataContent */ + protected static Dom\Element $metadataContent; - /** @var \DOMElement $customContent */ - protected static DOMElement $customContent; + /** @var \Dom\Element $customContent */ + protected static Dom\Element $customContent; /** @@ -86,9 +86,10 @@ public function testMarshalling(): void $metadataReference = new MetadataReference([$endpointReference]); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($metadataReference), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($metadataReference); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/MetadataExchange/XML/wsx/MetadataSectionTest.php b/tests/MetadataExchange/XML/wsx/MetadataSectionTest.php index 82ac3d8..48f41e5 100644 --- a/tests/MetadataExchange/XML/wsx/MetadataSectionTest.php +++ b/tests/MetadataExchange/XML/wsx/MetadataSectionTest.php @@ -63,9 +63,10 @@ public function testMarshalling(): void [$attr1], ); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($metadataSection), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($metadataSection); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); } } diff --git a/tests/MetadataExchange/XML/wsx/MetadataTest.php b/tests/MetadataExchange/XML/wsx/MetadataTest.php index 4de3624..c767aa0 100644 --- a/tests/MetadataExchange/XML/wsx/MetadataTest.php +++ b/tests/MetadataExchange/XML/wsx/MetadataTest.php @@ -72,10 +72,11 @@ public function testMarshalling(): void $metadata = new Metadata([$metadataSection], [new Chunk($child->documentElement)], [$attr1]); - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($metadata), - ); + $expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement); + $this->assertNotFalse($expectedXml); + $actualXml = strval($metadata); + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); }