Passed
Branch master (c86cc6)
by Tim
11:28
created

SignaturePropertyTest::testMarshalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6
7
use PHPUnit\Framework\TestCase;
8
use SimpleSAML\XML\Chunk;
9
use SimpleSAML\XML\DOMDocumentFactory;
10
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
11
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
12
use SimpleSAML\XMLSecurity\Constants as C;
13
use SimpleSAML\XMLSecurity\XML\ds\SignatureProperty;
14
15
use function dirname;
16
use function strval;
17
18
/**
19
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\SignaturePropertyTest
20
 *
21
 * @covers \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty
22
 * @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
23
 *
24
 * @package simplesamlphp/saml2
25
 */
26
final class SignaturePropertyTest extends TestCase
27
{
28
    use SchemaValidationTestTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TestUtils\SchemaValidationTestTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\T...s\SignaturePropertyTest: $documentElement, $ownerDocument, $message, $line
Loading history...
29
    use SerializableElementTestTrait;
0 ignored issues
show
Bug introduced by
The trait SimpleSAML\XML\TestUtils...lizableElementTestTrait requires the property $documentElement which is not provided by SimpleSAML\XMLSecurity\T...s\SignaturePropertyTest.
Loading history...
30
31
32
    /**
33
     */
34
    public static function setUpBeforeClass(): void
35
    {
36
        self::$testedClass = SignatureProperty::class;
37
38
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd';
39
40
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
41
            dirname(__FILE__, 3) . '/resources/xml/ds_SignatureProperty.xml',
42
        );
43
    }
44
45
46
    /**
47
     */
48
    public function testMarshalling(): void
49
    {
50
        $document = DOMDocumentFactory::fromString(
51
            '<ssp:HSMSerialNumber xmlns:ssp="urn:x-simplesamlphp:namespace">1234567890</ssp:HSMSerialNumber>'
52
        );
53
54
        $signatureProperty = new SignatureProperty(
55
            [new Chunk($document->documentElement)],
56
            'https://simplesamlphp.org/some/target',
57
            'abc123'
58
        );
59
60
        $this->assertEquals(
61
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
62
            strval($signatureProperty)
63
        );
64
    }
65
66
67
    /**
68
     */
69
    public function testUnmarshalling(): void
70
    {
71
        $signatureProperty = SignatureProperty::fromXML(self::$xmlRepresentation->documentElement);
72
73
        $this->assertEquals(
74
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
75
            strval($signatureProperty)
76
        );
77
    }
78
}
79