Passed
Push — master ( 5a07d0...30f015 )
by Tim
23:49 queued 11:01
created

X509SerialNumberTest::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
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 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 testUnmarshallingIncorrectTypeThrowsException(): void
59
    {
60
        $document = clone self::$xmlRepresentation;
61
        $document->documentElement->textContent = 'Not an integer';
62
63
        $this->expectException(SchemaViolationException::class);
64
        X509SerialNumber::fromXML($document->documentElement);
65
    }
66
}
67