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

XPathTest::testUnmarshalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6
7
use PHPUnit\Framework\TestCase;
8
use SimpleSAML\XML\DOMDocumentFactory;
9
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
10
use SimpleSAML\XMLSecurity\XML\ds\XPath;
11
12
use function dirname;
13
use function strval;
14
15
/**
16
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\XPathTest
17
 *
18
 * @covers \SimpleSAML\XMLSecurity\XML\ds\XPath
19
 *
20
 * @package simplesamlphp/xml-security
21
 */
22
class XPathTest extends TestCase
23
{
24
    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\Test\XML\ds\XPathTest.
Loading history...
25
26
27
    /**
28
     */
29
    public static function setUpBeforeClass(): void
30
    {
31
        self::$testedClass = XPath::class;
32
33
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
34
            dirname(__FILE__, 3) . '/resources/xml/ds_XPath.xml',
35
        );
36
    }
37
38
39
    public function testMarshalling(): void
40
    {
41
        $xpath = new XPath(
42
            'self::xenc:CipherValue[@Id="example1"]',
43
            [
44
                'xenc' => 'http://www.w3.org/2001/04/xmlenc#',
45
            ],
46
        );
47
48
        $this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression());
49
        $namespaces = $xpath->getNamespaces();
50
        $this->assertCount(1, $namespaces);
51
        $this->assertArrayHasKey('xenc', $namespaces);
0 ignored issues
show
Bug introduced by
It seems like $namespaces can also be of type Countable; however, parameter $array of PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept ArrayAccess|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $this->assertArrayHasKey('xenc', /** @scrutinizer ignore-type */ $namespaces);
Loading history...
52
        $this->assertEquals('http://www.w3.org/2001/04/xmlenc#', $namespaces['xenc']);
53
54
        $this->assertEquals(
55
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
56
            strval($xpath),
57
        );
58
    }
59
}
60