Passed
Push — master ( 2f478b...56a532 )
by Tim
02:08
created

SignatureMethodTest::testMarshallingElementOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 27
rs 9.7666
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 PHPUnit\Framework\Attributes\CoversClass;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\Chunk;
10
use SimpleSAML\XML\DOMDocumentFactory;
11
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
12
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13
use SimpleSAML\XMLSecurity\Constants as C;
14
use SimpleSAML\XMLSecurity\Utils\XPath;
15
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
16
use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength;
17
use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod;
18
19
use function dirname;
20
use function strval;
21
22
/**
23
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\SignatureMethodTest
24
 *
25
 * @package simplesamlphp/xml-security
26
 */
27
#[CoversClass(AbstractDsElement::class)]
28
#[CoversClass(SignatureMethod::class)]
29
final class SignatureMethodTest 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...\ds\SignatureMethodTest: $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...\ds\SignatureMethodTest.
Loading history...
33
34
    /**
35
     */
36
    public static function setUpBeforeClass(): void
37
    {
38
        self::$testedClass = SignatureMethod::class;
39
40
        self::$schemaFile = dirname(__FILE__, 3) . '/resources/schemas/simplesamlphp.xsd';
41
42
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
43
            dirname(__FILE__, 3) . '/resources/xml/ds_SignatureMethod.xml',
44
        );
45
    }
46
47
48
    /**
49
     */
50
    public function testMarshalling(): void
51
    {
52
        $hmacOutputLength = new HMACOutputLength('1234');
53
54
        $chunk = new Chunk(DOMDocumentFactory::fromString(
55
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
56
        )->documentElement);
57
58
        $signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]);
59
60
        $this->assertEquals(
61
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
62
            strval($signatureMethod),
63
        );
64
    }
65
66
67
    /**
68
     */
69
    public function testMarshallingElementOrder(): void
70
    {
71
        $hmacOutputLength = new HMACOutputLength('1234');
72
73
        $chunk = new Chunk(DOMDocumentFactory::fromString(
74
            '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
75
        )->documentElement);
76
77
        $signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]);
78
79
        $signatureMethodElement = $signatureMethod->toXML();
80
81
        $xpCache = XPath::getXPath($signatureMethodElement);
82
83
        $hmacOutputLength = XPath::xpQuery($signatureMethodElement, './ds:HMACOutputLength', $xpCache);
84
        $this->assertCount(1, $hmacOutputLength);
85
86
        /** @var \DOMElement[] $signatureMethodElements */
87
        $signatureMethodElements = XPath::xpQuery(
88
            $signatureMethodElement,
89
            './ds:HMACOutputLength/following-sibling::*',
90
            $xpCache,
91
        );
92
93
        // Test ordering of SignatureMethod contents
94
        $this->assertCount(1, $signatureMethodElements);
95
        $this->assertEquals('ssp:Chunk', $signatureMethodElements[0]->tagName);
96
    }
97
}
98