diff --git a/composer.json b/composer.json index 2b78b8b..df54cc6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.5", "ext-dom": "*", - "simplesamlphp/xml-cas": "~2.5", + "simplesamlphp/xml-cas": "dev-feature/dom-migration-php84", "simplesamlphp/xml-common": "dev-feature/dom-migration-php84" }, "require-dev": { diff --git a/src/XML/AbstractAttributes.php b/src/XML/AbstractAttributes.php index ebf9111..1f16a51 100644 --- a/src/XML/AbstractAttributes.php +++ b/src/XML/AbstractAttributes.php @@ -4,7 +4,7 @@ namespace SimpleSAML\Slate\XML; -use DOMElement; +use Dom; use SimpleSAML\CAS\XML\AbstractCasElement; use SimpleSAML\CAS\XML\AuthenticationDate; use SimpleSAML\CAS\XML\IsFromNewLogin; @@ -81,10 +81,10 @@ public function getIsFromNewLogin(): ?IsFromNewLogin /** * Convert this Attributes to XML. * - * @param \DOMElement|null $parent The element we should append this Attributes to. - * @return \DOMElement + * @param \Dom\Element|null $parent The element we should append this Attributes to. + * @return \Dom\Element */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = $this->instantiateParentElement($parent); diff --git a/src/XML/Attributes.php b/src/XML/Attributes.php index 34aa873..750bfe9 100644 --- a/src/XML/Attributes.php +++ b/src/XML/Attributes.php @@ -4,7 +4,7 @@ namespace SimpleSAML\Slate\XML; -use DOMElement; +use Dom; use SimpleSAML\CAS\Assert\Assert; use SimpleSAML\CAS\XML\AuthenticationDate; use SimpleSAML\CAS\XML\IsFromNewLogin; @@ -27,7 +27,7 @@ final class Attributes extends AbstractAttributes /** * Convert XML into a cas:attributes-element * - * @param \DOMElement $xml The XML element we should load + * @param \Dom\Element $xml The XML element we should load * @return static * * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException @@ -35,7 +35,7 @@ final class Attributes extends AbstractAttributes * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException * if the supplied element is missing one of the mandatory attributes */ - 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::getNamespaceURI(), InvalidDOMElementException::class); diff --git a/src/XML/AuthenticationSuccess.php b/src/XML/AuthenticationSuccess.php index c89301a..ac17f3e 100644 --- a/src/XML/AuthenticationSuccess.php +++ b/src/XML/AuthenticationSuccess.php @@ -4,7 +4,7 @@ namespace SimpleSAML\Slate\XML; -use DOMElement; +use Dom; use SimpleSAML\CAS\Assert\Assert; use SimpleSAML\CAS\XML\Proxies; use SimpleSAML\CAS\XML\ProxyGrantingTicket; @@ -54,7 +54,7 @@ final public function __construct( /** * Convert XML into a cas:authenticationSuccess-element * - * @param \DOMElement $xml The XML element we should load + * @param \Dom\Element $xml The XML element we should load * @return static * * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException @@ -62,7 +62,7 @@ final public function __construct( * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException * if the supplied element is missing one of the mandatory attributes */ - 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::getNamespaceURI(), InvalidDOMElementException::class); @@ -99,10 +99,10 @@ public static function fromXML(DOMElement $xml): static /** * Convert this AuthenticationSuccess to XML. * - * @param \DOMElement|null $parent The element we should append this AuthenticationSuccess to. - * @return \DOMElement + * @param \Dom\Element|null $parent The element we should append this AuthenticationSuccess to. + * @return \Dom\Element */ - public function toXML(?DOMElement $parent = null): DOMElement + public function toXML(?Dom\Element $parent = null): Dom\Element { $e = $this->instantiateParentElement($parent); diff --git a/src/XML/ServiceResponse.php b/src/XML/ServiceResponse.php index 106b03a..6ed08b2 100644 --- a/src/XML/ServiceResponse.php +++ b/src/XML/ServiceResponse.php @@ -4,7 +4,7 @@ namespace SimpleSAML\Slate\XML; -use DOMElement; +use Dom; use SimpleSAML\CAS\Assert\Assert; use SimpleSAML\CAS\XML\AbstractServiceResponse; use SimpleSAML\CAS\XML\AuthenticationFailure; @@ -32,7 +32,7 @@ final class ServiceResponse extends AbstractServiceResponse implements SchemaVal /** * Convert XML into a cas:serviceResponse-element * - * @param \DOMElement $xml The XML element we should load + * @param \Dom\Element $xml The XML element we should load * @return static * * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException @@ -40,7 +40,7 @@ final class ServiceResponse extends AbstractServiceResponse implements SchemaVal * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException * if the supplied element is missing one of the mandatory attributes */ - 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::getNamespaceURI(), InvalidDOMElementException::class); diff --git a/tests/Slate/XML/AttributesTest.php b/tests/Slate/XML/AttributesTest.php index cd167d7..396b98f 100644 --- a/tests/Slate/XML/AttributesTest.php +++ b/tests/Slate/XML/AttributesTest.php @@ -59,20 +59,20 @@ public function testMarshalling(): void $longTerm = LongTermAuthenticationRequestTokenUsed::fromString('true'); $isFromNewLogin = IsFromNewLogin::fromString('true'); - /** @var \DOMElement $firstNameElt */ + /** @var \Dom\Element $firstNameElt */ $firstNameElt = DOMDocumentFactory::fromString( 'Example', )->documentElement; $firstName = new Chunk($firstNameElt); - /** @var \DOMElement $lastNameElt */ + /** @var \Dom\Element $lastNameElt */ $lastNameElt = DOMDocumentFactory::fromString( 'User', )->documentElement; $lastName = new Chunk($lastNameElt); - /** @var \DOMElement $emailElt */ + /** @var \Dom\Element $emailElt */ $emailElt = DOMDocumentFactory::fromString( 'example-user@technolutions.com', )->documentElement; @@ -82,11 +82,11 @@ public function testMarshalling(): void 'myValue', ); - /** @var \DOMElement $elt */ + /** @var \Dom\Element $elt */ $elt = $document->documentElement; $myAttribute = new Chunk($elt); - /** @var \DOMElement $customAttrElt */ + /** @var \Dom\Element $customAttrElt */ $customAttrElt = DOMDocumentFactory::fromString( 'customAttribute', )->documentElement; @@ -115,7 +115,7 @@ public function testMarshallingElementOrdering(): void 'myValue', ); - /** @var \DOMElement $elt */ + /** @var \Dom\Element $elt */ $elt = $document->documentElement; $myAttribute = new Chunk($elt); $attributes = new Attributes($authenticationDate, $longTerm, $isFromNewLogin, [$myAttribute]); @@ -128,7 +128,7 @@ public function testMarshallingElementOrdering(): void $this->assertCount(1, $attributesElements); // Test ordering of cas:attributes contents - /** @var \DOMElement[] $attributesElements */ + /** @var \Dom\Element[] $attributesElements */ $attributesElements = XPath::xpQuery( $attributesElement, './cas:authenticationDate/following-sibling::*', @@ -148,7 +148,7 @@ public function testMarshallingElementOrdering(): void */ public function testFromXMLPopulatesTypedPropertiesAndFiltersStandardChildren(): void { - /** @var \DOMElement $element */ + /** @var \Dom\Element $element */ $element = self::$xmlRepresentation->documentElement; $attributes = Attributes::fromXML($element); @@ -193,7 +193,7 @@ public function testFromXMLWithOnlyExtensionAttributes(): void XML; - /** @var \DOMElement $element */ + /** @var \Dom\Element $element */ $element = DOMDocumentFactory::fromString($xml)->documentElement; $attributes = Attributes::fromXML($element); @@ -225,7 +225,7 @@ public function testFromXMLWithDuplicateStandardChildThrows(): void XML; - /** @var \DOMElement $element */ + /** @var \Dom\Element $element */ $element = DOMDocumentFactory::fromString($xml)->documentElement; $this->expectException(MissingElementException::class); diff --git a/tests/Slate/XML/AuthenticationSuccessTest.php b/tests/Slate/XML/AuthenticationSuccessTest.php index 1e20157..c2b9387 100644 --- a/tests/Slate/XML/AuthenticationSuccessTest.php +++ b/tests/Slate/XML/AuthenticationSuccessTest.php @@ -58,26 +58,26 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - /** @var \DOMElement $firstNameElt */ + /** @var \Dom\Element $firstNameElt */ $firstNameElt = DOMDocumentFactory::fromString( 'Example', )->documentElement; $firstName = new Chunk($firstNameElt); - /** @var \DOMElement $lastNameElt */ + /** @var \Dom\Element $lastNameElt */ $lastNameElt = DOMDocumentFactory::fromString( 'User', )->documentElement; $lastName = new Chunk($lastNameElt); - /** @var \DOMElement $emailElt */ + /** @var \Dom\Element $emailElt */ $emailElt = DOMDocumentFactory::fromString( 'example-user@technolutions.com', )->documentElement; $email = new Chunk($emailElt); - /** @var \DOMElement $customAttrElt */ + /** @var \Dom\Element $customAttrElt */ $customAttrElt = DOMDocumentFactory::fromString( 'customAttribute', )->documentElement; @@ -100,7 +100,7 @@ public function testMarshalling(): void new Proxy(StringValue::fromString('https://proxy1/pgtUrl')), ]); - /** @var \DOMElement $personElt */ + /** @var \Dom\Element $personElt */ $personElt = DOMDocumentFactory::fromString( // phpcs:ignore Generic.Files.LineLength '345d2e1b-65de-419c-96ce-e1866d4c57cd', @@ -108,14 +108,14 @@ public function testMarshalling(): void $person = new Chunk($personElt); - /** @var \DOMElement $roundElt */ + /** @var \Dom\Element $roundElt */ $roundElt = DOMDocumentFactory::fromString( 'Regular Decision', )->documentElement; $round = new Chunk($roundElt); - /** @var \DOMElement $refElt */ + /** @var \Dom\Element $refElt */ $refElt = DOMDocumentFactory::fromString( '774482874', )->documentElement; @@ -139,20 +139,20 @@ public function testMarshalling(): void public function testMarshallingElementOrdering(): void { - /** @var \DOMElement $firstNameElt */ + /** @var \Dom\Element $firstNameElt */ $firstNameElt = DOMDocumentFactory::fromString( 'John', )->documentElement; $firstName = new Chunk($firstNameElt); - /** @var \DOMElement $lastNameElt */ + /** @var \Dom\Element $lastNameElt */ $lastNameElt = DOMDocumentFactory::fromString( 'Doe', )->documentElement; $lastName = new Chunk($lastNameElt); - /** @var \DOMElement $emailElt */ + /** @var \Dom\Element $emailElt */ $emailElt = DOMDocumentFactory::fromString( 'jdoe@example.org', )->documentElement; @@ -170,7 +170,7 @@ public function testMarshallingElementOrdering(): void Proxy::fromString('https://proxy1/pgtUrl'), ]); - /** @var \DOMElement $personElt */ + /** @var \Dom\Element $personElt */ $personElt = DOMDocumentFactory::fromString( // phpcs:ignore Generic.Files.LineLength '345d2e1b-65de-419c-96ce-e1866d4c57cd', @@ -178,14 +178,14 @@ public function testMarshallingElementOrdering(): void $person = new Chunk($personElt); - /** @var \DOMElement $roundElt */ + /** @var \Dom\Element $roundElt */ $roundElt = DOMDocumentFactory::fromString( 'Regular Decision', )->documentElement; $round = new Chunk($roundElt); - /** @var \DOMElement $refElt */ + /** @var \Dom\Element $refElt */ $refElt = DOMDocumentFactory::fromString( '774482874', )->documentElement; @@ -207,7 +207,7 @@ public function testMarshallingElementOrdering(): void $this->assertCount(1, $authenticationSuccessElements); // Test ordering of cas:authenticationSuccess contents - /** @var \DOMElement[] $authenticationSuccessElements */ + /** @var \Dom\Element[] $authenticationSuccessElements */ $authenticationSuccessElements = XPath::xpQuery( $authenticationSuccessElement, './cas:user/following-sibling::*', @@ -236,7 +236,7 @@ public function testAuthenticationSuccessElementsContainOnlySlateChildren(): voi dirname(__FILE__, 3) . '/resources/xml/slate_authenticationSuccess.xml', ); - /** @var \DOMElement $element */ + /** @var \Dom\Element $element */ $element = $doc->documentElement; $authenticationSuccess = AuthenticationSuccess::fromXML($element); @@ -276,7 +276,7 @@ public function testAuthenticationSuccessElementsContainOnlySlateChildren(): voi */ public function testFromXMLNestedAttributesAreFilteredAndTyped(): void { - /** @var \DOMElement $element */ + /** @var \Dom\Element $element */ $element = self::$xmlRepresentation->documentElement; $authenticationSuccess = AuthenticationSuccess::fromXML($element); diff --git a/tests/Slate/XML/ServiceResponseTest.php b/tests/Slate/XML/ServiceResponseTest.php index 83dcba2..2c62df4 100644 --- a/tests/Slate/XML/ServiceResponseTest.php +++ b/tests/Slate/XML/ServiceResponseTest.php @@ -4,16 +4,16 @@ namespace SimpleSAML\Slate\Test\XML; -use DOMDocument; use PHPUnit\Framework\TestCase; use SimpleSAML\Slate\XML\AuthenticationSuccess; use SimpleSAML\Slate\XML\ServiceResponse; +use SimpleSAML\XML\DOMDocumentFactory; final class ServiceResponseTest extends TestCase { public function testFromXMLWithAuthenticationSuccessReturnsSlateAuthenticationSuccess(): void { - $doc = new DOMDocument('1.0', 'UTF-8'); + $doc = DOMDocumentFactory::create(); // Build element with the correct namespace/localName $serviceResponseElement = $doc->createElementNS( @@ -33,8 +33,8 @@ public function testFromXMLWithAuthenticationSuccessReturnsSlateAuthenticationSu $userElement = $doc->createElementNS( ServiceResponse::getNamespaceURI(), 'cas:user', - 'some-user', ); + $userElement->textContent = 'some-user'; $authSuccessElement->appendChild($userElement); // Required child: ...