Passed
Pull Request — master (#60)
by Tim
03:27 queued 01:12
created

X509CertificateTest::testMarshallingInvalidBase64()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
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, Group};
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...
Bug introduced by
The type PHPUnit\Framework\Attributes\Group 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\DOMDocumentFactory;
10
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11
use SimpleSAML\XML\Type\Base64BinaryValue;
12
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
13
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
14
use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509Certificate};
15
16
use function dirname;
17
use function str_replace;
18
use function strval;
19
20
/**
21
 * Class \SimpleSAML\XMLSecurity\Test\XML\ds\X509CertificateTest
22
 *
23
 * @package simplesamlphp/xml-security
24
 */
25
#[Group('ds')]
26
#[CoversClass(AbstractDsElement::class)]
27
#[CoversClass(X509Certificate::class)]
28
final class X509CertificateTest extends TestCase
29
{
30
    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\X509CertificateTest.
Loading history...
31
32
    /** @var string */
33
    private static string $certificate;
34
35
36
    /**
37
     */
38
    public static function setUpBeforeClass(): void
39
    {
40
        self::$testedClass = X509Certificate::class;
41
42
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
43
            dirname(__FILE__, 3) . '/resources/xml/ds_X509Certificate.xml',
44
        );
45
46
        self::$certificate = str_replace(
47
            [
48
                '-----BEGIN CERTIFICATE-----',
49
                '-----END CERTIFICATE-----',
50
                '-----BEGIN RSA PUBLIC KEY-----',
51
                '-----END RSA PUBLIC KEY-----',
52
                "\r\n",
53
                "\n",
54
            ],
55
            [
56
                '',
57
                '',
58
                '',
59
                '',
60
                "\n",
61
                '',
62
            ],
63
            PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE),
64
        );
65
    }
66
67
68
    /**
69
     */
70
    public function testMarshalling(): void
71
    {
72
        $x509cert = new X509Certificate(
73
            Base64BinaryValue::fromString(self::$certificate),
74
        );
75
76
        $this->assertEquals(
77
            XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
78
            strval($x509cert),
79
        );
80
    }
81
}
82