Skip to content

Commit 422277f

Browse files
committed
Migrate DOM-classes to PHP 8.4's new DOM-API
1 parent 4c1a544 commit 422277f

99 files changed

Lines changed: 713 additions & 638 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"ext-dom": "*",
1515

1616
"simplesamlphp/assert": "~2.0",
17-
"simplesamlphp/xml-common": "~2.8",
18-
"simplesamlphp/xml-ws-addressing": "~1.3",
19-
"simplesamlphp/xml-ws-policy": "~1.3",
20-
"simplesamlphp/xml-wss-core": "~1.4"
17+
"simplesamlphp/xml-common": "dev-feature/dom-migration-php84",
18+
"simplesamlphp/xml-ws-addressing": "dev-feature/dom-migration-php84",
19+
"simplesamlphp/xml-ws-policy": "dev-feature/dom-migration-php84",
20+
"simplesamlphp/xml-wss-core": "dev-feature/dom-migration-php84"
2121
},
2222
"require-dev": {
2323
"simplesamlphp/simplesamlphp-test-framework": "~1.11"

src/TestUtils/sp_200507/NestedPolicyTypeTestTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public function testMarshalling(): void
2626
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\AbstractNestedPolicyType $np */
2727
$np = new static::$testedClass([static::$policy, static::$some], [static::$attr]);
2828

29-
$this->assertEquals(
30-
static::$xmlRepresentation->saveXML(static::$xmlRepresentation->documentElement),
31-
strval($np),
32-
);
29+
$expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement);
30+
$this->assertNotFalse($expectedXml);
31+
$actualXml = strval($np);
32+
33+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
3334
}
3435
}

src/TestUtils/sp_200702/NestedPolicyTypeTestTrait.php

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ public function testMarshalling(): void
2929
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractNestedPolicyType $np */
3030
$np = new static::$testedClass([static::$chunk], [static::$attr]);
3131

32-
$this->assertEquals(
33-
static::$xmlRepresentation->saveXML(static::$xmlRepresentation->documentElement),
34-
strval($np),
35-
);
32+
$expectedXml = static::$xmlRepresentation->saveXml(static::$xmlRepresentation->documentElement);
33+
$this->assertNotFalse($expectedXml);
34+
$actualXml = strval($np);
35+
36+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
3637
}
3738

3839

@@ -55,10 +56,11 @@ public function testMarshallingWithoutNSAttr(): void
5556
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractNestedPolicyType $np */
5657
$np = new static::$testedClass([static::$chunk]);
5758

58-
$this->assertEquals(
59-
$xmlRepresentation->saveXML($xmlRepresentation->documentElement),
60-
strval($np),
61-
);
59+
$expectedXml = $xmlRepresentation->saveXml($xmlRepresentation->documentElement);
60+
$this->assertNotFalse($expectedXml);
61+
$actualXml = strval($np);
62+
63+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
6264
}
6365

6466

@@ -75,12 +77,13 @@ public function testMarshallingWithoutChildren(): void
7577
$xmlRepresentation = DOMDocumentFactory::fromString($xml);
7678

7779
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractNestedPolicyType $qns */
78-
$qns = new static::$testedClass([], [static::$attr]);
80+
$np = new static::$testedClass([], [static::$attr]);
7981

80-
$this->assertEquals(
81-
$xmlRepresentation->saveXML($xmlRepresentation->documentElement),
82-
strval($qns),
83-
);
82+
$expectedXml = $xmlRepresentation->saveXml($xmlRepresentation->documentElement);
83+
$this->assertNotFalse($expectedXml);
84+
$actualXml = strval($np);
85+
86+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
8487
}
8588

8689

@@ -127,10 +130,11 @@ public function testUnmarshallingWithoutNSAttr(): void
127130
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractNestedPolicyType $np */
128131
$np = static::$testedClass::fromXML($xmlRepresentation->documentElement);
129132

130-
$this->assertEquals(
131-
$xmlRepresentation->saveXML($xmlRepresentation->documentElement),
132-
strval($np),
133-
);
133+
$expectedXml = $xmlRepresentation->saveXml($xmlRepresentation->documentElement);
134+
$this->assertNotFalse($expectedXml);
135+
$actualXml = strval($np);
136+
137+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
134138
}
135139

136140

@@ -150,9 +154,10 @@ public function testUnmarshallingWithoutChildren(): void
150154
/** @var \SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractNestedPolicyType $np */
151155
$np = static::$testedClass::fromXML($xmlRepresentation->documentElement);
152156

153-
$this->assertEquals(
154-
$xmlRepresentation->saveXML($xmlRepresentation->documentElement),
155-
strval($np),
156-
);
157+
$expectedXml = $xmlRepresentation->saveXml($xmlRepresentation->documentElement);
158+
$this->assertNotFalse($expectedXml);
159+
$actualXml = strval($np);
160+
161+
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
157162
}
158163
}

src/Utils/XPath.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\Utils;
66

7-
use DOMNode;
8-
use DOMXPath;
7+
use Dom;
98
use SimpleSAML\WebServices\SecurityPolicy\Constants as C;
109

1110
/**
@@ -16,15 +15,15 @@
1615
class XPath extends \SimpleSAML\XPath\XPath
1716
{
1817
/*
19-
* Get a DOMXPath object that can be used to search for WS Security elements.
18+
* Get a Dom\XPath object that can be used to search for WS Security elements.
2019
*
21-
* @param \DOMNode $node The document to associate to the DOMXPath object.
20+
* @param \Dom\Node $node The document to associate to the Dom\XPath object.
2221
* @param bool $autoregister Whether to auto-register all namespaces used in the document
2322
*
24-
* @return \DOMXPath A DOMXPath object ready to use in the given document, with several
23+
* @return \Dom\XPath A Dom\XPath object ready to use in the given document, with several
2524
* ws-related namespaces already registered.
2625
*/
27-
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
26+
public static function getXPath(Dom\Node $node, bool $autoregister = false): Dom\XPath
2827
{
2928
$xp = parent::getXPath($node, $autoregister);
3029

src/XML/sp_200507/AbstractEmptyType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
1010

@@ -30,12 +30,12 @@ final public function __construct()
3030
*
3131
* Note: this method cannot be used when extending this class, if the constructor has a different signature.
3232
*
33-
* @param \DOMElement $xml The XML element we should load.
33+
* @param \Dom\Element $xml The XML element we should load.
3434
*
3535
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
3636
* if the qualified name of the supplied element is wrong
3737
*/
38-
public static function fromXML(DOMElement $xml): static
38+
public static function fromXML(Dom\Element $xml): static
3939
{
4040
$qualifiedName = static::getClassName(static::class);
4141
Assert::eq(
@@ -53,7 +53,7 @@ public static function fromXML(DOMElement $xml): static
5353
/**
5454
* Convert this element to XML.
5555
*/
56-
public function toXML(?DOMElement $parent = null): DOMElement
56+
public function toXML(?Dom\Element $parent = null): Dom\Element
5757
{
5858
return $this->instantiateParentElement($parent);
5959
}

src/XML/sp_200507/AbstractHeaderType.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\XML\ExtendableAttributesTrait;
1010
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
@@ -77,12 +77,12 @@ public function getNamespace(): AnyURIValue
7777
*
7878
* Note: this method cannot be used when extending this class, if the constructor has a different signature.
7979
*
80-
* @param \DOMElement $xml The XML element we should load.
80+
* @param \Dom\Element $xml The XML element we should load.
8181
*
8282
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
8383
* if the qualified name of the supplied element is wrong
8484
*/
85-
public static function fromXML(DOMElement $xml): static
85+
public static function fromXML(Dom\Element $xml): static
8686
{
8787
$qualifiedName = static::getClassName(static::class);
8888
Assert::eq(
@@ -95,9 +95,10 @@ public static function fromXML(DOMElement $xml): static
9595
$namespacedAttributes = self::getAttributesNSFromXML($xml);
9696
$namespace = self::getAttribute($xml, 'Namespace', AnyURIValue::class);
9797

98+
$name = $xml->getAttribute('Name');
9899
return new static(
99100
$namespace,
100-
$xml->hasAttribute('Name') ? QNameValue::fromString($xml->getAttribute('Name')) : null,
101+
($name !== null) ? QNameValue::fromString($name) : null,
101102
$namespacedAttributes,
102103
);
103104
}
@@ -106,7 +107,7 @@ public static function fromXML(DOMElement $xml): static
106107
/**
107108
* Convert this element to XML.
108109
*/
109-
public function toXML(?DOMElement $parent = null): DOMElement
110+
public function toXML(?Dom\Element $parent = null): Dom\Element
110111
{
111112
$e = $this->instantiateParentElement($parent);
112113

src/XML/sp_200507/AbstractHttpsTokenType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\XML\ExtendableAttributesTrait;
1010
use SimpleSAML\XML\ExtendableElementTrait;
@@ -68,12 +68,12 @@ public function getRequireClientCertificate(): BooleanValue
6868
/**
6969
* Initialize an HttpsTokenType.
7070
*
71-
* @param \DOMElement $xml The XML element we should load.
71+
* @param \Dom\Element $xml The XML element we should load.
7272
*
7373
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
7474
* if the qualified name of the supplied element is wrong
7575
*/
76-
public static function fromXML(DOMElement $xml): static
76+
public static function fromXML(Dom\Element $xml): static
7777
{
7878
$qualifiedName = static::getClassName(static::class);
7979
Assert::eq(
@@ -94,7 +94,7 @@ public static function fromXML(DOMElement $xml): static
9494
/**
9595
* Convert this element to XML.
9696
*/
97-
public function toXML(?DOMElement $parent = null): DOMElement
97+
public function toXML(?Dom\Element $parent = null): Dom\Element
9898
{
9999
$e = $this->instantiateParentElement($parent);
100100

src/XML/sp_200507/AbstractIssuedTokenType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type\IncludeTokenValue;
1010
use SimpleSAML\XML\ExtendableAttributesTrait;
@@ -95,7 +95,7 @@ public function getRequestSecurityTokenTemplate(): RequestSecurityTokenTemplate
9595
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
9696
* if the qualified name of the supplied element is wrong
9797
*/
98-
public static function fromXML(DOMElement $xml): static
98+
public static function fromXML(Dom\Element $xml): static
9999
{
100100
$qualifiedName = static::getClassName(static::class);
101101
Assert::eq(
@@ -124,7 +124,7 @@ public static function fromXML(DOMElement $xml): static
124124
/**
125125
* Convert this element to XML.
126126
*/
127-
public function toXML(?DOMElement $parent = null): DOMElement
127+
public function toXML(?Dom\Element $parent = null): Dom\Element
128128
{
129129
$e = $this->instantiateParentElement($parent);
130130

src/XML/sp_200507/AbstractNestedPolicyType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\XML\ExtendableAttributesTrait;
1010
use SimpleSAML\XML\ExtendableElementTrait;
@@ -50,7 +50,7 @@ final public function __construct(
5050
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
5151
* if the qualified name of the supplied element is wrong
5252
*/
53-
public static function fromXML(DOMElement $xml): static
53+
public static function fromXML(Dom\Element $xml): static
5454
{
5555
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
5656
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
@@ -65,7 +65,7 @@ public static function fromXML(DOMElement $xml): static
6565
/**
6666
* Convert this AbstractNestedPolicyType to XML.
6767
*/
68-
public function toXML(?DOMElement $parent = null): DOMElement
68+
public function toXML(?Dom\Element $parent = null): Dom\Element
6969
{
7070
$e = $this->instantiateParentElement($parent);
7171

src/XML/sp_200507/AbstractQNameAssertionType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\WebServices\SecurityPolicy\Assert\Assert;
99
use SimpleSAML\XML\ExtendableAttributesTrait;
1010
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
@@ -46,7 +46,7 @@ final public function __construct(
4646
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
4747
* if the qualified name of the supplied element is wrong
4848
*/
49-
public static function fromXML(DOMElement $xml): static
49+
public static function fromXML(Dom\Element $xml): static
5050
{
5151
$qualifiedName = static::getClassName(static::class);
5252
Assert::eq(
@@ -64,7 +64,7 @@ public static function fromXML(DOMElement $xml): static
6464
/**
6565
* Convert this element to XML.
6666
*/
67-
public function toXML(?DOMElement $parent = null): DOMElement
67+
public function toXML(?Dom\Element $parent = null): Dom\Element
6868
{
6969
$e = $this->instantiateParentElement($parent);
7070

0 commit comments

Comments
 (0)