Passed
Branch master (c86cc6)
by Tim
03:54
created

X509SerialNumberTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 6 1
A testMarshalling() 0 7 1
A testUnmarshallingIncorrectTypeThrowsException() 0 7 1
A testUnmarshalling() 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\XML\Constants as C;
10
use SimpleSAML\XML\DOMDocumentFactory;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13
use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber;
14
15
use function dirname;
16
use function strval;
17
18
/**
19
 * Class \SimpleSAML\XMLSecurity\XML\ds\X509SerialNumberTest
20
 *
21
 * @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
22
 * @covers \SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber
23
 *
24
 * @package simplesamlphp/xml-security
25
 */
26
final class X509SerialNumberTest extends TestCase
27
{
28
    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...ds\X509SerialNumberTest.
Loading history...
29
30
31
    /**
32
     */
33
    public static function setUpBeforeClass(): void
34
    {
35
        self::$testedClass = X509SerialNumber::class;
36
37
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
38
            dirname(__FILE__, 3) . '/resources/xml/ds_X509SerialNumber.xml',
39
        );
40
    }
41
42
43
    /**
44
     */
45
    public function testMarshalling(): void
46
    {
47
        $serialNumber = new X509SerialNumber('123456');
48
49
        $this->assertEquals(
50
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
51
            strval($serialNumber),
52
        );
53
    }
54
55
56
    /**
57
     */
58
    public function testUnmarshalling(): void
59
    {
60
        $serialNumber = X509SerialNumber::fromXML(self::$xmlRepresentation->documentElement);
61
62
        $this->assertEquals(
63
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
64
            strval($serialNumber),
65
        );
66
    }
67
68
69
    /**
70
     */
71
    public function testUnmarshallingIncorrectTypeThrowsException(): void
72
    {
73
        $document = clone self::$xmlRepresentation;
74
        $document->documentElement->textContent = 'Not an integer';
75
76
        $this->expectException(SchemaViolationException::class);
77
        X509SerialNumber::fromXML($document->documentElement);
78
    }
79
}
80