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

CipherReferenceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnmarshalling() 0 7 1
A setUpBeforeClass() 0 13 1
A testMarshalling() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\xenc;
6
7
use PHPUnit\Framework\TestCase;
8
use SimpleSAML\XML\DOMDocumentFactory;
9
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
10
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11
use SimpleSAML\XMLSecurity\Constants as C;
12
use SimpleSAML\XMLSecurity\XML\ds\Transform;
13
use SimpleSAML\XMLSecurity\XML\ds\XPath;
14
use SimpleSAML\XMLSecurity\XML\xenc\CipherReference;
15
use SimpleSAML\XMLSecurity\XML\xenc\Transforms;
16
17
use function dirname;
18
use function strval;
19
20
/**
21
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\CipherReferenceTest
22
 *
23
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
24
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractReference
25
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\CipherReference
26
 *
27
 * @package simplesamlphp/xml-security
28
 */
29
final class CipherReferenceTest extends TestCase
30
{
31
    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...enc\CipherReferenceTest: $documentElement, $ownerDocument, $message, $line
Loading history...
32
    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...enc\CipherReferenceTest.
Loading history...
33
34
    /** @var \SimpleSAML\XMLSecurity\XML\xenc\Transforms $transforms */
35
    private static Transforms $transforms;
36
37
38
    /**
39
     */
40
    public static function setUpBeforeClass(): void
41
    {
42
        self::$testedClass = CipherReference::class;
43
44
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xenc-schema.xsd';
45
46
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
47
            dirname(__FILE__, 3) . '/resources/xml/xenc_CipherReference.xml',
48
        );
49
50
        $xpath = new XPath('count(//. | //@* | //namespace::*)');
51
        $transform = new Transform(C::XPATH_URI, $xpath);
52
        self::$transforms = new Transforms([$transform]);
53
    }
54
55
56
    // marshalling
57
58
59
    /**
60
     */
61
    public function testMarshalling(): void
62
    {
63
        $cipherReference = new CipherReference('#Cipher_VALUE_ID', [self::$transforms]);
64
65
        $this->assertEquals(
66
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
67
            strval($cipherReference),
68
        );
69
    }
70
71
72
    // unmarshalling
73
74
75
    /**
76
     */
77
    public function testUnmarshalling(): void
78
    {
79
        $cipherReference = CipherReference::fromXML(self::$xmlRepresentation->documentElement);
80
81
        $this->assertEquals(
82
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
83
            strval($cipherReference),
84
        );
85
    }
86
}
87