From e36196e30bd2ba305cc75d6c7f5c9ac711429e54 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 25 Jan 2024 21:00:09 +0100 Subject: [PATCH] Raise coverage --- src/XML/fed/AbstractPseudonymBasisType.php | 12 ------------ src/XML/fed/AbstractRelativeToType.php | 2 +- ...r.php => FederationMetadataHandlerTest.php} | 0 .../XML/fed/ReferenceToken11Test.php | 15 +++++++++++++++ .../WSSecurity/XML/fed/ReferenceTokenTest.php | 15 +++++++++++++++ tests/WSSecurity/XML/fed/RelativeToTest.php | 16 ++++++++++++++++ tests/WSSecurity/XML/wst/CodeTest.php | 1 + tests/WSSecurity/XML/wst/ComputedKeyTest.php | 1 + tests/WSSecurity/XML/wst/KeyTypeTest.php | 1 + tests/WSSecurity/XML/wst/ParticipantsTest.php | 18 +++++++++++++++++- tests/WSSecurity/XML/wst/SignChallengeTest.php | 11 +++++++++++ tests/WSSecurity/XML/wst/StatusTest.php | 1 + 12 files changed, 79 insertions(+), 14 deletions(-) rename tests/WSSecurity/XML/fed/{FederationMetadataHandler.php => FederationMetadataHandlerTest.php} (100%) diff --git a/src/XML/fed/AbstractPseudonymBasisType.php b/src/XML/fed/AbstractPseudonymBasisType.php index da250cb0..f104d4f6 100644 --- a/src/XML/fed/AbstractPseudonymBasisType.php +++ b/src/XML/fed/AbstractPseudonymBasisType.php @@ -47,18 +47,6 @@ final public function __construct( } - /** - * Test if an object, at the state it's in, would produce an empty XML-element - * - * @return bool - */ - public function isEmptyElement(): bool - { - return empty($this->getElements()) - && empty($this->getAttributesNS()); - } - - /** * Create an instance of this object from its XML representation. * diff --git a/src/XML/fed/AbstractRelativeToType.php b/src/XML/fed/AbstractRelativeToType.php index 69e7285a..73ca60ff 100644 --- a/src/XML/fed/AbstractRelativeToType.php +++ b/src/XML/fed/AbstractRelativeToType.php @@ -36,7 +36,7 @@ abstract class AbstractRelativeToType extends AbstractFedElement * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes */ final public function __construct( - array $children, + array $children = [], array $namespacedAttributes = [] ) { $this->setElements($children); diff --git a/tests/WSSecurity/XML/fed/FederationMetadataHandler.php b/tests/WSSecurity/XML/fed/FederationMetadataHandlerTest.php similarity index 100% rename from tests/WSSecurity/XML/fed/FederationMetadataHandler.php rename to tests/WSSecurity/XML/fed/FederationMetadataHandlerTest.php diff --git a/tests/WSSecurity/XML/fed/ReferenceToken11Test.php b/tests/WSSecurity/XML/fed/ReferenceToken11Test.php index 6d0b7e7b..7dd44744 100644 --- a/tests/WSSecurity/XML/fed/ReferenceToken11Test.php +++ b/tests/WSSecurity/XML/fed/ReferenceToken11Test.php @@ -74,4 +74,19 @@ public function testMarshalling(): void strval($referenceToken11), ); } + + + /** + * Adding an empty X509lToken element should yield an empty element. + */ + public function testMarshallingEmptyElement(): void + { + $fedns = C::NS_FED; + $referenceToken11 = new ReferenceToken11(); + $this->assertEquals( + "", + strval($referenceToken11), + ); + $this->assertTrue($referenceToken11->isEmptyElement()); + } } diff --git a/tests/WSSecurity/XML/fed/ReferenceTokenTest.php b/tests/WSSecurity/XML/fed/ReferenceTokenTest.php index 61951173..04691418 100644 --- a/tests/WSSecurity/XML/fed/ReferenceTokenTest.php +++ b/tests/WSSecurity/XML/fed/ReferenceTokenTest.php @@ -135,4 +135,19 @@ public function testMarshalling(): void strval($referenceToken) ); } + + + /** + * Adding an empty ReferenceToken element should yield an empty element. + */ + public function testMarshallingEmptyElement(): void + { + $fedns = C::NS_FED; + $referenceToken = new ReferenceToken(); + $this->assertEquals( + "", + strval($referenceToken), + ); + $this->assertTrue($referenceToken->isEmptyElement()); + } } diff --git a/tests/WSSecurity/XML/fed/RelativeToTest.php b/tests/WSSecurity/XML/fed/RelativeToTest.php index 58d620c0..5b38803e 100644 --- a/tests/WSSecurity/XML/fed/RelativeToTest.php +++ b/tests/WSSecurity/XML/fed/RelativeToTest.php @@ -5,6 +5,7 @@ namespace SimpleSAML\Test\WSSecurity\XML\fed; use PHPUnit\Framework\TestCase; +use SimpleSAML\WSSecurity\Constants as C; use SimpleSAML\WSSecurity\XML\fed\RelativeTo; use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\Chunk; @@ -66,4 +67,19 @@ public function testMarshalling(): void strval($relativeTo), ); } + + + /** + * Adding an empty RelativeTo element should yield an empty element. + */ + public function testMarshallingEmptyElement(): void + { + $fedns = C::NS_FED; + $relativeTo = new RelativeTo(); + $this->assertEquals( + "", + strval($relativeTo), + ); + $this->assertTrue($relativeTo->isEmptyElement()); + } } diff --git a/tests/WSSecurity/XML/wst/CodeTest.php b/tests/WSSecurity/XML/wst/CodeTest.php index 136b0f18..7f952822 100644 --- a/tests/WSSecurity/XML/wst/CodeTest.php +++ b/tests/WSSecurity/XML/wst/CodeTest.php @@ -16,6 +16,7 @@ * Class \SimpleSAML\WSSecurity\XML\wst\CodeTest * * @covers \SimpleSAML\WSSecurity\XML\wst\Code + * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractStatusCodeOpenEnum * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement * * @package tvdijen/ws-security diff --git a/tests/WSSecurity/XML/wst/ComputedKeyTest.php b/tests/WSSecurity/XML/wst/ComputedKeyTest.php index 75ad84c3..4b97b8b5 100644 --- a/tests/WSSecurity/XML/wst/ComputedKeyTest.php +++ b/tests/WSSecurity/XML/wst/ComputedKeyTest.php @@ -17,6 +17,7 @@ * Class \SimpleSAML\WSSecurity\XML\wst\ComputedKeyTest * * @covers \SimpleSAML\WSSecurity\XML\wst\ComputedKey + * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractComputedKeyOpenEnum * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement * * @package tvdijen/ws-security diff --git a/tests/WSSecurity/XML/wst/KeyTypeTest.php b/tests/WSSecurity/XML/wst/KeyTypeTest.php index de819055..fb299252 100644 --- a/tests/WSSecurity/XML/wst/KeyTypeTest.php +++ b/tests/WSSecurity/XML/wst/KeyTypeTest.php @@ -17,6 +17,7 @@ * Class \SimpleSAML\WSSecurity\XML\wst\KeyTypeTest * * @covers \SimpleSAML\WSSecurity\XML\wst\KeyType + * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractKeyTypeOpenEnum * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement * * @package tvdijen/ws-security diff --git a/tests/WSSecurity/XML/wst/ParticipantsTest.php b/tests/WSSecurity/XML/wst/ParticipantsTest.php index 544ff04d..5abb9004 100644 --- a/tests/WSSecurity/XML/wst/ParticipantsTest.php +++ b/tests/WSSecurity/XML/wst/ParticipantsTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\Constants as C; use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\Participant; use SimpleSAML\WSSecurity\XML\wst\Participants; @@ -21,7 +22,7 @@ * Class \SimpleSAML\WSSecurity\XML\wst\ParticipantsTest * * @covers \SimpleSAML\WSSecurity\XML\wst\Participants - * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractParticipantType + * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractParticipantsType * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement * * @package tvdijen/ws-security @@ -66,4 +67,19 @@ public function testMarshalling(): void strval($participants), ); } + + + /** + * Adding an empty Participants element should yield an empty element. + */ + public function testMarshallingEmptyElement(): void + { + $wstns = C::NS_TRUST; + $participants = new Participants(); + $this->assertEquals( + "", + strval($participants), + ); + $this->assertTrue($participants->isEmptyElement()); + } } diff --git a/tests/WSSecurity/XML/wst/SignChallengeTest.php b/tests/WSSecurity/XML/wst/SignChallengeTest.php index cfa4c973..dcfb5a6e 100644 --- a/tests/WSSecurity/XML/wst/SignChallengeTest.php +++ b/tests/WSSecurity/XML/wst/SignChallengeTest.php @@ -66,4 +66,15 @@ public function testMarshalling(): void strval($signChallenge), ); } + + + /** + * Test creating an empty SignChallenge object from scratch. + */ + public function testMarshallingEmpty(): void + { + $signChallenge = new SignChallenge(); + + $this->assertTrue($signChallenge->isEmptyElement()); + } } diff --git a/tests/WSSecurity/XML/wst/StatusTest.php b/tests/WSSecurity/XML/wst/StatusTest.php index 8c907408..e8bdf923 100644 --- a/tests/WSSecurity/XML/wst/StatusTest.php +++ b/tests/WSSecurity/XML/wst/StatusTest.php @@ -19,6 +19,7 @@ * Class \SimpleSAML\WSSecurity\XML\wst\StatusTest * * @covers \SimpleSAML\WSSecurity\XML\wst\Status + * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractStatusType * @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement * * @package tvdijen/ws-security