From ef39b9301e1ede88aac3ed607a96a6123e6e8ada Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 2 Sep 2024 12:45:57 +0200 Subject: [PATCH] Raise coverage --- src/SAML2/XML/saml/AttributeValue.php | 23 ++++++++++++--------- tests/SAML2/XML/saml/AttributeValueTest.php | 23 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/SAML2/XML/saml/AttributeValue.php b/src/SAML2/XML/saml/AttributeValue.php index cba71f90b..0b136f7d7 100644 --- a/src/SAML2/XML/saml/AttributeValue.php +++ b/src/SAML2/XML/saml/AttributeValue.php @@ -52,7 +52,8 @@ final public function __construct( */ public function getXsiType(): string { - $type = gettype($this->value); + $value = $this->getValue(); + $type = gettype($value); switch ($type) { case "integer": @@ -60,14 +61,14 @@ public function getXsiType(): string case "NULL": return "xs:nil"; case "object": - if ($this->value instanceof DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return 'xs:dateTime'; } return sprintf( '%s:%s', - $this->value::getNamespacePrefix(), - AbstractElement::getClassName(get_class($this->value)), + $value::getNamespacePrefix(), + AbstractElement::getClassName(get_class($value)), ); default: return "xs:string"; @@ -138,6 +139,7 @@ public static function fromXML(DOMElement $xml): static $xml->getAttributeNS(C::NS_XSI, "nil") === "true") ) { Assert::isEmpty($xml->textContent); + $value = null; } else { $value = $xml->textContent; @@ -158,7 +160,8 @@ public function toXML(DOMElement $parent = null): DOMElement { $e = parent::instantiateParentElement($parent); - $type = gettype($this->value); + $value = $this->getValue(); + $type = gettype($value); switch ($type) { case "integer": @@ -166,7 +169,7 @@ public function toXML(DOMElement $parent = null): DOMElement $e->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', C::NS_XSI); $e->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xs', C::NS_XS); $e->setAttributeNS(C::NS_XSI, 'xsi:type', 'xs:integer'); - $e->textContent = strval($this->getValue()); + $e->textContent = strval($value); break; case "NULL": $e->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', C::NS_XSI); @@ -174,17 +177,17 @@ public function toXML(DOMElement $parent = null): DOMElement $e->textContent = ''; break; case "object": - if ($this->value instanceof DateTimeInterface) { + if ($value instanceof DateTimeInterface) { $e->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', C::NS_XSI); $e->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xs', C::NS_XS); $e->setAttributeNS(C::NS_XSI, 'xsi:type', 'xs:dateTime'); - $e->textContent = $this->value->format(C::DATETIME_FORMAT); + $e->textContent = $value->format(C::DATETIME_FORMAT); } else { - $this->getValue()->toXML($e); + $value->toXML($e); } break; default: // string - $e->textContent = $this->getValue(); + $e->textContent = $value; break; } diff --git a/tests/SAML2/XML/saml/AttributeValueTest.php b/tests/SAML2/XML/saml/AttributeValueTest.php index 01cb01bb4..66b14ad44 100644 --- a/tests/SAML2/XML/saml/AttributeValueTest.php +++ b/tests/SAML2/XML/saml/AttributeValueTest.php @@ -87,6 +87,17 @@ public function testMarshallingInteger(): void $this->assertEquals(3, $av->getValue()); $this->assertEquals('xs:integer', $av->getXsiType()); + + $nssaml = C::NS_SAML; + $nsxs = C::NS_XS; + $nsxsi = C::NS_XSI; + $xml = <<3 +XML; + $this->assertEquals( + $xml, + strval($av), + ); } @@ -101,6 +112,17 @@ public function testMarshallingDateTime(): void $value = $av->getValue(); $this->assertEquals('2024-04-04T04:44:44Z', $value->format(C::DATETIME_FORMAT)); $this->assertEquals('xs:dateTime', $av->getXsiType()); + + $nssaml = C::NS_SAML; + $nsxs = C::NS_XS; + $nsxsi = C::NS_XSI; + $xml = <<2024-04-04T04:44:44Z +XML; + $this->assertEquals( + $xml, + strval($av), + ); } @@ -111,6 +133,7 @@ public function testMarshallingNull(): void $av = new AttributeValue(null); $this->assertNull($av->getValue()); $this->assertEquals('xs:nil', $av->getXsiType()); + $nssaml = C::NS_SAML; $nsxsi = C::NS_XSI; $xml = <<