-
Notifications
You must be signed in to change notification settings - Fork 3
Development
All projects within the SimpleSAMLphp namespace follow PSR-12 coding style.
We also use phpunit
, psalm
, phpcs
and scrutinizer
for code quality and codecov
for code coverage.
Testing an element extending AbstractElement
is fairly simple.
To properly test your XML-structures, you SHOULD add testMarshalling
and testUnmarshalling` (*):
(*): Marshalling
SHOULD use all the setter
methods and Unmarshalling
SHOULD use all the getter
methods in a class.
Both tests should use a pre-defined xml-file set in the xmlRepresentation
property, and a reference to the fully
qualified class name set in the testedClass
property.
-
testMarshalling
:
$element = new Element(2, false, 'text');
$this->assertEquals(
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement),
strval($element),
);
-
testUnmarshalling
:
$element = Element::fromXML($this->xmlRepresentation->documentElement);
$this->assertEquals(
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement),
strval($element),
);
-
Additional tests should be added to cover 'missing required' during
Marshalling
, same for 'missing required' duringUnmarshalling
. -
Elements that COULD render into an empty element SHOULD implement
isEmptyElement()
and should have a unit tests to cover for bothMarshalling
andUnmarshalling
. -
SerializableElementTestTrait
:
You SHOULD use the SerializationTestTrait
to make sure marshalling/unmarshalling an element produces the same output.
-
ArrayizableElementTestTrait
:
Simple elements that implement toArray
and fromArray
SHOULD implement this trait to make sure marshalling/unmarshalling
an element produces the same output.
-
SchemaValidationTestTrait
:
Elements that implement a certain xsd-schema SHOULD implement this trait to test output against their xsd-schema.
Set the schema
property on the unit-test class to point to the xsd-schema file.