Passed
Push — master ( be09b3...67068d )
by Tim
13:28
created

TransformsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
c 3
b 0
f 0
dl 0
loc 51
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 6 1
A testMarshalling() 0 16 1
A testMarshallingEmptyElement() 0 9 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\SerializableElementTestTrait;
10
use SimpleSAML\XMLSecurity\Constants as C;
11
use SimpleSAML\XMLSecurity\XML\ds\Transform;
12
use SimpleSAML\XMLSecurity\XML\ds\XPath;
13
use SimpleSAML\XMLSecurity\XML\xenc\Transforms;
14
15
use function dirname;
16
use function strval;
17
18
/**
19
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\TransformsTest
20
 *
21
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\Transforms
22
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
23
 *
24
 * @package simplesamlphp/xml-security
25
 */
26
final class TransformsTest 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...XML\xenc\TransformsTest.
Loading history...
29
30
31
    /**
32
     */
33
    public static function setUpBeforeClass(): void
34
    {
35
        self::$testedClass = Transforms::class;
36
37
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
38
            dirname(__FILE__, 3) . '/resources/xml/xenc_Transforms.xml',
39
        );
40
    }
41
42
43
    /**
44
     */
45
    public function testMarshalling(): void
46
    {
47
        $transforms = new Transforms(
48
            [
49
                new Transform(
50
                    C::XPATH_URI,
51
                    new XPath(
52
                        'count(//. | //@* | //namespace::*)',
53
                    ),
54
                ),
55
            ],
56
        );
57
58
        $this->assertEquals(
59
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
60
            strval($transforms),
61
        );
62
    }
63
64
65
    /**
66
     * Adding an empty Transforms element should yield an empty element.
67
     */
68
    public function testMarshallingEmptyElement(): void
69
    {
70
        $xenc_ns = Transforms::NS;
71
        $transforms = new Transforms([]);
72
        $this->assertEquals(
73
            "<xenc:Transforms xmlns:xenc=\"$xenc_ns\"/>",
74
            strval($transforms),
75
        );
76
        $this->assertTrue($transforms->isEmptyElement());
77
    }
78
}
79