Skip to content

Commit

Permalink
Implement generic version of testUnmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 25, 2023
1 parent 2b1a1f5 commit c495092
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 64 deletions.
38 changes: 32 additions & 6 deletions src/TestUtils/SerializableElementTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,38 @@ trait SerializableElementTestTrait
protected static DOMDocument $xmlRepresentation;


/**
* Test creating XML from a class.
*/
abstract public function testMarshalling(): void;


/**
* Test creating a class from XML.
*/
public function testUnmarshalling(): void
{
if (!class_exists(self::$testedClass)) {
$this->markTestSkipped(
'Unable to run ' . self::class . '::testUnmarshalling(). Please set ' . self::class
. ':$testedClass to a class-string representing the XML-class being tested',
);
} elseif (empty(self::$xmlRepresentation)) {
$this->markTestSkipped(
'Unable to run ' . self::class . '::testUnmarshalling(). Please set ' . self::class
. ':$xmlRepresentation to a DOMDocument representing the XML-class being tested',
);
} else {
$elt = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($elt),
);
}
}


/**
* Test serialization / unserialization.
*
Expand All @@ -47,10 +79,4 @@ public function testSerialization(): void
);
}
}


abstract public function testMarshalling(): void;


abstract public function testUnmarshalling(): void;
}
1 change: 1 addition & 0 deletions tests/XML/AbstractElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testMarshalling(): void

/**
*/
#[Override]

Check failure on line 57 in tests/XML/AbstractElementTest.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedAttributeClass

tests/XML/AbstractElementTest.php:57:7: UndefinedAttributeClass: Attribute class SimpleSAML\Test\XML\Override does not exist (see https://psalm.dev/241)
public function testUnmarshalling(): void
{
$element = Element::fromXML(self::$xmlRepresentation->documentElement);
Expand Down
1 change: 1 addition & 0 deletions tests/XML/Base64ElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function testMarshalling(): void

/**
*/
#[Override]

Check failure on line 60 in tests/XML/Base64ElementTraitTest.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedAttributeClass

tests/XML/Base64ElementTraitTest.php:60:7: UndefinedAttributeClass: Attribute class SimpleSAML\Test\XML\Override does not exist (see https://psalm.dev/241)
public function testUnmarshalling(): void
{
$base64Element = Base64Element::fromXML(self::$xmlRepresentation->documentElement);
Expand Down
1 change: 1 addition & 0 deletions tests/XML/ChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testMarshalling(): void

/**
*/
#[Override]

Check failure on line 56 in tests/XML/ChunkTest.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedAttributeClass

tests/XML/ChunkTest.php:56:7: UndefinedAttributeClass: Attribute class SimpleSAML\Test\XML\Override does not exist (see https://psalm.dev/241)
public function testUnmarshalling(): void
{
$element = Chunk::fromXML(self::$xmlRepresentation->documentElement);
Expand Down
13 changes: 0 additions & 13 deletions tests/XML/ExtendableAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,4 @@ public function testMarshalling(): void
strval($extendableElement),
);
}


/**
*/
public function testUnmarshalling(): void
{
$extendableElement = ExtendableAttributesElement::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($extendableElement),
);
}
}
13 changes: 0 additions & 13 deletions tests/XML/ExtendableElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,4 @@ public function testMarshalling(): void
strval($extendableElement),
);
}


/**
*/
public function testUnmarshalling(): void
{
$extendableElement = ExtendableElement::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($extendableElement),
);
}
}
11 changes: 0 additions & 11 deletions tests/XML/LocalizedStringElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,4 @@ public function testMarshalling(): void
strval($localizedStringElement),
);
}


/**
*/
public function testUnmarshalling(): void
{
$localizedStringElement = LocalizedStringElement::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals('en', $localizedStringElement->getLanguage());
$this->assertEquals('test', $localizedStringElement->getContent());
}
}
11 changes: 0 additions & 11 deletions tests/XML/QNameElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ public function testMarshallingInvalidQualifiedNameThrowsException(): void
}


/**
*/
public function testUnmarshalling(): void
{
$qnameElement = QNameElement::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals('env:Sender', $qnameElement->getContent());
$this->assertEquals('http://www.w3.org/2003/05/soap-envelope', $qnameElement->getContentNamespaceUri());
}


/**
*/
public function testUnmarshallingNonNamepacedQualifiedName(): void
Expand Down
10 changes: 0 additions & 10 deletions tests/XML/StringElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,4 @@ public function testMarshalling(): void
strval($stringElement),
);
}


/**
*/
public function testUnmarshalling(): void
{
$stringElement = StringElement::fromXML(self::$xmlRepresentation->documentElement);

$this->assertEquals('test', $stringElement->getContent());
}
}

0 comments on commit c495092

Please sign in to comment.