Skip to content

Commit 036b9f8

Browse files
committed
Migrate DOM-classes to PHP 8.4's new DOM-API
1 parent 7155f57 commit 036b9f8

8 files changed

Lines changed: 46 additions & 46 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^8.5",
1414
"ext-dom": "*",
1515

16-
"simplesamlphp/xml-cas": "~2.5",
16+
"simplesamlphp/xml-cas": "dev-feature/dom-migration-php84",
1717
"simplesamlphp/xml-common": "dev-feature/dom-migration-php84"
1818
},
1919
"require-dev": {

src/XML/AbstractAttributes.php

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

55
namespace SimpleSAML\Slate\XML;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\CAS\XML\AbstractCasElement;
99
use SimpleSAML\CAS\XML\AuthenticationDate;
1010
use SimpleSAML\CAS\XML\IsFromNewLogin;
@@ -81,10 +81,10 @@ public function getIsFromNewLogin(): ?IsFromNewLogin
8181
/**
8282
* Convert this Attributes to XML.
8383
*
84-
* @param \DOMElement|null $parent The element we should append this Attributes to.
85-
* @return \DOMElement
84+
* @param \Dom\Element|null $parent The element we should append this Attributes to.
85+
* @return \Dom\Element
8686
*/
87-
public function toXML(?DOMElement $parent = null): DOMElement
87+
public function toXML(?Dom\Element $parent = null): Dom\Element
8888
{
8989
$e = $this->instantiateParentElement($parent);
9090

src/XML/Attributes.php

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

55
namespace SimpleSAML\Slate\XML;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\CAS\Assert\Assert;
99
use SimpleSAML\CAS\XML\AuthenticationDate;
1010
use SimpleSAML\CAS\XML\IsFromNewLogin;
@@ -27,15 +27,15 @@ final class Attributes extends AbstractAttributes
2727
/**
2828
* Convert XML into a cas:attributes-element
2929
*
30-
* @param \DOMElement $xml The XML element we should load
30+
* @param \Dom\Element $xml The XML element we should load
3131
* @return static
3232
*
3333
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
3434
* if the qualified name of the supplied element is wrong
3535
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
3636
* if the supplied element is missing one of the mandatory attributes
3737
*/
38-
public static function fromXML(DOMElement $xml): static
38+
public static function fromXML(Dom\Element $xml): static
3939
{
4040
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
4141
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);

src/XML/AuthenticationSuccess.php

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

55
namespace SimpleSAML\Slate\XML;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\CAS\Assert\Assert;
99
use SimpleSAML\CAS\XML\Proxies;
1010
use SimpleSAML\CAS\XML\ProxyGrantingTicket;
@@ -54,15 +54,15 @@ final public function __construct(
5454
/**
5555
* Convert XML into a cas:authenticationSuccess-element
5656
*
57-
* @param \DOMElement $xml The XML element we should load
57+
* @param \Dom\Element $xml The XML element we should load
5858
* @return static
5959
*
6060
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
6161
* if the qualified name of the supplied element is wrong
6262
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
6363
* if the supplied element is missing one of the mandatory attributes
6464
*/
65-
public static function fromXML(DOMElement $xml): static
65+
public static function fromXML(Dom\Element $xml): static
6666
{
6767
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
6868
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
@@ -99,10 +99,10 @@ public static function fromXML(DOMElement $xml): static
9999
/**
100100
* Convert this AuthenticationSuccess to XML.
101101
*
102-
* @param \DOMElement|null $parent The element we should append this AuthenticationSuccess to.
103-
* @return \DOMElement
102+
* @param \Dom\Element|null $parent The element we should append this AuthenticationSuccess to.
103+
* @return \Dom\Element
104104
*/
105-
public function toXML(?DOMElement $parent = null): DOMElement
105+
public function toXML(?Dom\Element $parent = null): Dom\Element
106106
{
107107
$e = $this->instantiateParentElement($parent);
108108

src/XML/ServiceResponse.php

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

55
namespace SimpleSAML\Slate\XML;
66

7-
use DOMElement;
7+
use Dom;
88
use SimpleSAML\CAS\Assert\Assert;
99
use SimpleSAML\CAS\XML\AbstractServiceResponse;
1010
use SimpleSAML\CAS\XML\AuthenticationFailure;
@@ -32,15 +32,15 @@ final class ServiceResponse extends AbstractServiceResponse implements SchemaVal
3232
/**
3333
* Convert XML into a cas:serviceResponse-element
3434
*
35-
* @param \DOMElement $xml The XML element we should load
35+
* @param \Dom\Element $xml The XML element we should load
3636
* @return static
3737
*
3838
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
3939
* if the qualified name of the supplied element is wrong
4040
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
4141
* if the supplied element is missing one of the mandatory attributes
4242
*/
43-
public static function fromXML(DOMElement $xml): static
43+
public static function fromXML(Dom\Element $xml): static
4444
{
4545
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
4646
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);

tests/Slate/XML/AttributesTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ public function testMarshalling(): void
5959
$longTerm = LongTermAuthenticationRequestTokenUsed::fromString('true');
6060
$isFromNewLogin = IsFromNewLogin::fromString('true');
6161

62-
/** @var \DOMElement $firstNameElt */
62+
/** @var \Dom\Element $firstNameElt */
6363
$firstNameElt = DOMDocumentFactory::fromString(
6464
'<cas:firstname xmlns:cas="http://www.yale.edu/tp/cas">Example</cas:firstname>',
6565
)->documentElement;
6666

6767
$firstName = new Chunk($firstNameElt);
6868

69-
/** @var \DOMElement $lastNameElt */
69+
/** @var \Dom\Element $lastNameElt */
7070
$lastNameElt = DOMDocumentFactory::fromString(
7171
'<cas:lastname xmlns:cas="http://www.yale.edu/tp/cas">User</cas:lastname>',
7272
)->documentElement;
7373
$lastName = new Chunk($lastNameElt);
7474

75-
/** @var \DOMElement $emailElt */
75+
/** @var \Dom\Element $emailElt */
7676
$emailElt = DOMDocumentFactory::fromString(
7777
'<cas:email xmlns:cas="http://www.yale.edu/tp/cas">example-user@technolutions.com</cas:email>',
7878
)->documentElement;
@@ -82,11 +82,11 @@ public function testMarshalling(): void
8282
'<cas:myAttribute xmlns:cas="http://www.yale.edu/tp/cas">myValue</cas:myAttribute>',
8383
);
8484

85-
/** @var \DOMElement $elt */
85+
/** @var \Dom\Element $elt */
8686
$elt = $document->documentElement;
8787
$myAttribute = new Chunk($elt);
8888

89-
/** @var \DOMElement $customAttrElt */
89+
/** @var \Dom\Element $customAttrElt */
9090
$customAttrElt = DOMDocumentFactory::fromString(
9191
'<slate:custom xmlns:slate="http://technolutions.com/slate">customAttribute</slate:custom>',
9292
)->documentElement;
@@ -115,7 +115,7 @@ public function testMarshallingElementOrdering(): void
115115
'<cas:myAttribute xmlns:cas="http://www.yale.edu/tp/cas">myValue</cas:myAttribute>',
116116
);
117117

118-
/** @var \DOMElement $elt */
118+
/** @var \Dom\Element $elt */
119119
$elt = $document->documentElement;
120120
$myAttribute = new Chunk($elt);
121121
$attributes = new Attributes($authenticationDate, $longTerm, $isFromNewLogin, [$myAttribute]);
@@ -128,7 +128,7 @@ public function testMarshallingElementOrdering(): void
128128
$this->assertCount(1, $attributesElements);
129129

130130
// Test ordering of cas:attributes contents
131-
/** @var \DOMElement[] $attributesElements */
131+
/** @var \Dom\Element[] $attributesElements */
132132
$attributesElements = XPath::xpQuery(
133133
$attributesElement,
134134
'./cas:authenticationDate/following-sibling::*',
@@ -148,7 +148,7 @@ public function testMarshallingElementOrdering(): void
148148
*/
149149
public function testFromXMLPopulatesTypedPropertiesAndFiltersStandardChildren(): void
150150
{
151-
/** @var \DOMElement $element */
151+
/** @var \Dom\Element $element */
152152
$element = self::$xmlRepresentation->documentElement;
153153

154154
$attributes = Attributes::fromXML($element);
@@ -193,7 +193,7 @@ public function testFromXMLWithOnlyExtensionAttributes(): void
193193
</cas:attributes>
194194
XML;
195195

196-
/** @var \DOMElement $element */
196+
/** @var \Dom\Element $element */
197197
$element = DOMDocumentFactory::fromString($xml)->documentElement;
198198

199199
$attributes = Attributes::fromXML($element);
@@ -225,7 +225,7 @@ public function testFromXMLWithDuplicateStandardChildThrows(): void
225225
</cas:attributes>
226226
XML;
227227

228-
/** @var \DOMElement $element */
228+
/** @var \Dom\Element $element */
229229
$element = DOMDocumentFactory::fromString($xml)->documentElement;
230230

231231
$this->expectException(MissingElementException::class);

tests/Slate/XML/AuthenticationSuccessTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,26 @@ public static function setUpBeforeClass(): void
5858
*/
5959
public function testMarshalling(): void
6060
{
61-
/** @var \DOMElement $firstNameElt */
61+
/** @var \Dom\Element $firstNameElt */
6262
$firstNameElt = DOMDocumentFactory::fromString(
6363
'<cas:firstname xmlns:cas="http://www.yale.edu/tp/cas">Example</cas:firstname>',
6464
)->documentElement;
6565

6666
$firstName = new Chunk($firstNameElt);
6767

68-
/** @var \DOMElement $lastNameElt */
68+
/** @var \Dom\Element $lastNameElt */
6969
$lastNameElt = DOMDocumentFactory::fromString(
7070
'<cas:lastname xmlns:cas="http://www.yale.edu/tp/cas">User</cas:lastname>',
7171
)->documentElement;
7272
$lastName = new Chunk($lastNameElt);
7373

74-
/** @var \DOMElement $emailElt */
74+
/** @var \Dom\Element $emailElt */
7575
$emailElt = DOMDocumentFactory::fromString(
7676
'<cas:email xmlns:cas="http://www.yale.edu/tp/cas">example-user@technolutions.com</cas:email>',
7777
)->documentElement;
7878
$email = new Chunk($emailElt);
7979

80-
/** @var \DOMElement $customAttrElt */
80+
/** @var \Dom\Element $customAttrElt */
8181
$customAttrElt = DOMDocumentFactory::fromString(
8282
'<slate:custom xmlns:slate="http://technolutions.com/slate">customAttribute</slate:custom>',
8383
)->documentElement;
@@ -100,22 +100,22 @@ public function testMarshalling(): void
100100
new Proxy(StringValue::fromString('https://proxy1/pgtUrl')),
101101
]);
102102

103-
/** @var \DOMElement $personElt */
103+
/** @var \Dom\Element $personElt */
104104
$personElt = DOMDocumentFactory::fromString(
105105
// phpcs:ignore Generic.Files.LineLength
106106
'<slate:person xmlns:slate="http://technolutions.com/slate">345d2e1b-65de-419c-96ce-e1866d4c57cd</slate:person>',
107107
)->documentElement;
108108

109109
$person = new Chunk($personElt);
110110

111-
/** @var \DOMElement $roundElt */
111+
/** @var \Dom\Element $roundElt */
112112
$roundElt = DOMDocumentFactory::fromString(
113113
'<slate:round xmlns:slate="http://technolutions.com/slate">Regular Decision</slate:round>',
114114
)->documentElement;
115115

116116
$round = new Chunk($roundElt);
117117

118-
/** @var \DOMElement $refElt */
118+
/** @var \Dom\Element $refElt */
119119
$refElt = DOMDocumentFactory::fromString(
120120
'<slate:ref xmlns:slate="http://technolutions.com/slate">774482874</slate:ref>',
121121
)->documentElement;
@@ -139,20 +139,20 @@ public function testMarshalling(): void
139139

140140
public function testMarshallingElementOrdering(): void
141141
{
142-
/** @var \DOMElement $firstNameElt */
142+
/** @var \Dom\Element $firstNameElt */
143143
$firstNameElt = DOMDocumentFactory::fromString(
144144
'<cas:firstname xmlns:cas="http://www.yale.edu/tp/cas">John</cas:firstname>',
145145
)->documentElement;
146146

147147
$firstName = new Chunk($firstNameElt);
148148

149-
/** @var \DOMElement $lastNameElt */
149+
/** @var \Dom\Element $lastNameElt */
150150
$lastNameElt = DOMDocumentFactory::fromString(
151151
'<cas:lastname xmlns:cas="http://www.yale.edu/tp/cas">Doe</cas:lastname>',
152152
)->documentElement;
153153
$lastName = new Chunk($lastNameElt);
154154

155-
/** @var \DOMElement $emailElt */
155+
/** @var \Dom\Element $emailElt */
156156
$emailElt = DOMDocumentFactory::fromString(
157157
'<cas:email xmlns:cas="http://www.yale.edu/tp/cas">jdoe@example.org</cas:email>',
158158
)->documentElement;
@@ -170,22 +170,22 @@ public function testMarshallingElementOrdering(): void
170170
Proxy::fromString('https://proxy1/pgtUrl'),
171171
]);
172172

173-
/** @var \DOMElement $personElt */
173+
/** @var \Dom\Element $personElt */
174174
$personElt = DOMDocumentFactory::fromString(
175175
// phpcs:ignore Generic.Files.LineLength
176176
'<slate:person xmlns:slate="http://technolutions.com/slate">345d2e1b-65de-419c-96ce-e1866d4c57cd</slate:person>',
177177
)->documentElement;
178178

179179
$person = new Chunk($personElt);
180180

181-
/** @var \DOMElement $roundElt */
181+
/** @var \Dom\Element $roundElt */
182182
$roundElt = DOMDocumentFactory::fromString(
183183
'<slate:round xmlns:slate="http://technolutions.com/slate">Regular Decision</slate:round>',
184184
)->documentElement;
185185

186186
$round = new Chunk($roundElt);
187187

188-
/** @var \DOMElement $refElt */
188+
/** @var \Dom\Element $refElt */
189189
$refElt = DOMDocumentFactory::fromString(
190190
'<slate:ref xmlns:slate="http://technolutions.com/slate">774482874</slate:ref>',
191191
)->documentElement;
@@ -207,7 +207,7 @@ public function testMarshallingElementOrdering(): void
207207
$this->assertCount(1, $authenticationSuccessElements);
208208

209209
// Test ordering of cas:authenticationSuccess contents
210-
/** @var \DOMElement[] $authenticationSuccessElements */
210+
/** @var \Dom\Element[] $authenticationSuccessElements */
211211
$authenticationSuccessElements = XPath::xpQuery(
212212
$authenticationSuccessElement,
213213
'./cas:user/following-sibling::*',
@@ -236,7 +236,7 @@ public function testAuthenticationSuccessElementsContainOnlySlateChildren(): voi
236236
dirname(__FILE__, 3) . '/resources/xml/slate_authenticationSuccess.xml',
237237
);
238238

239-
/** @var \DOMElement $element */
239+
/** @var \Dom\Element $element */
240240
$element = $doc->documentElement;
241241

242242
$authenticationSuccess = AuthenticationSuccess::fromXML($element);
@@ -276,7 +276,7 @@ public function testAuthenticationSuccessElementsContainOnlySlateChildren(): voi
276276
*/
277277
public function testFromXMLNestedAttributesAreFilteredAndTyped(): void
278278
{
279-
/** @var \DOMElement $element */
279+
/** @var \Dom\Element $element */
280280
$element = self::$xmlRepresentation->documentElement;
281281

282282
$authenticationSuccess = AuthenticationSuccess::fromXML($element);

tests/Slate/XML/ServiceResponseTest.php

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

55
namespace SimpleSAML\Slate\Test\XML;
66

7-
use DOMDocument;
87
use PHPUnit\Framework\TestCase;
98
use SimpleSAML\Slate\XML\AuthenticationSuccess;
109
use SimpleSAML\Slate\XML\ServiceResponse;
10+
use SimpleSAML\XML\DOMDocumentFactory;
1111

1212
final class ServiceResponseTest extends TestCase
1313
{
1414
public function testFromXMLWithAuthenticationSuccessReturnsSlateAuthenticationSuccess(): void
1515
{
16-
$doc = new DOMDocument('1.0', 'UTF-8');
16+
$doc = DOMDocumentFactory::create();
1717

1818
// Build <cas:serviceResponse> element with the correct namespace/localName
1919
$serviceResponseElement = $doc->createElementNS(
@@ -33,8 +33,8 @@ public function testFromXMLWithAuthenticationSuccessReturnsSlateAuthenticationSu
3333
$userElement = $doc->createElementNS(
3434
ServiceResponse::getNamespaceURI(),
3535
'cas:user',
36-
'some-user',
3736
);
37+
$userElement->textContent = 'some-user';
3838
$authSuccessElement->appendChild($userElement);
3939

4040
// Required child: <cas:attributes>...</cas:attributes>

0 commit comments

Comments
 (0)