Passed
Branch master (c86cc6)
by Tim
01:57
created

DigestValueTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMarshallingNotBase64() 0 4 1
A setUpBeforeClass() 0 8 1
A testUnmarshalling() 0 7 1
A testMarshalling() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6
7
use DOMDocument;
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\Assert\AssertionFailedException;
10
use SimpleSAML\XML\DOMDocumentFactory;
11
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
12
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
14
use SimpleSAML\XMLSecurity\XML\ds\DigestValue;
15
16
use function dirname;
17
use function strval;
18
19
/**
20
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\DigestValueTest
21
 *
22
 * @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
23
 * @covers \SimpleSAML\XMLSecurity\XML\ds\DigestValue
24
 *
25
 * @package simplesamlphp/xml-security
26
 */
27
final class DigestValueTest extends TestCase
28
{
29
    use SchemaValidationTestTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TestUtils\SchemaValidationTestTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\Test\XML\ds\DigestValueTest: $documentElement, $ownerDocument, $message, $line
Loading history...
30
    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\Test\XML\ds\DigestValueTest.
Loading history...
31
32
    /**
33
     */
34
    public static function setUpBeforeClass(): void
35
    {
36
        self::$testedClass = DigestValue::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_DigestValue.xml',
42
        );
43
    }
44
45
46
    /**
47
     */
48
    public function testMarshalling(): void
49
    {
50
        $digestValue = new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
51
52
        $this->assertEquals(
53
            XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
54
            strval($digestValue),
55
        );
56
    }
57
58
59
    /**
60
     */
61
    public function testMarshallingNotBase64(): void
62
    {
63
        $this->expectException(AssertionFailedException::class);
64
        new DigestValue('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
65
    }
66
67
68
    /**
69
     */
70
    public function testUnmarshalling(): void
71
    {
72
        $digestValue = DigestValue::fromXML(self::$xmlRepresentation->documentElement);
73
74
        $this->assertEquals(
75
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
76
            strval($digestValue),
77
        );
78
    }
79
}
80