1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
12
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; |
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
|
|
|
* @package simplesamlphp/xml-security |
22
|
|
|
*/ |
23
|
|
|
#[CoversClass(AbstractDsElement::class)] |
24
|
|
|
#[CoversClass(X509SerialNumber::class)] |
25
|
|
|
final class X509SerialNumberTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
use SerializableElementTestTrait; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
*/ |
32
|
|
|
public static function setUpBeforeClass(): void |
33
|
|
|
{ |
34
|
|
|
self::$testedClass = X509SerialNumber::class; |
35
|
|
|
|
36
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
37
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_X509SerialNumber.xml', |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
*/ |
44
|
|
|
public function testMarshalling(): void |
45
|
|
|
{ |
46
|
|
|
$serialNumber = new X509SerialNumber('123456'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( |
49
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
50
|
|
|
strval($serialNumber), |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
*/ |
57
|
|
|
public function testUnmarshallingIncorrectTypeThrowsException(): void |
58
|
|
|
{ |
59
|
|
|
$document = clone self::$xmlRepresentation; |
60
|
|
|
/** @var \DOMElement $docElement */ |
61
|
|
|
$docElement = $document->documentElement; |
62
|
|
|
$docElement->textContent = 'Not an integer'; |
63
|
|
|
|
64
|
|
|
$this->expectException(SchemaViolationException::class); |
65
|
|
|
X509SerialNumber::fromXML($docElement); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|