Passed
Push — master ( 6d2edc...84c866 )
by Tim
01:33
created

SerializableElementTestTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSerialization() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Test\XML;
6
7
use DOMDocument;
8
9
use function class_exists;
10
11
/**
12
 * Test for Serializable XML classes to perform default serialization tests.
13
 *
14
 * @package simplesamlphp\xml-common
15
 */
16
trait SerializableElementTestTrait
17
{
18
    /** @var class-string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
19
    protected string $testedClass;
20
21
    /** @var \DOMDocument|null */
22
    protected ?DOMDocument $xmlRepresentation = null;
23
24
25
    /**
26
     * Test serialization / unserialization.
27
     */
28
    public function testSerialization(): void
29
    {
30
        if (!class_exists($this->testedClass)) {
31
            $this->markTestSkipped(
0 ignored issues
show
Bug introduced by
It seems like markTestSkipped() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
            $this->/** @scrutinizer ignore-call */ 
32
                   markTestSkipped(
Loading history...
32
                'Unable to run ' . self::class . '::testSerialization(). Please set ' . self::class
33
                . ':$testedClass to a class-string representing the XML-class being tested',
34
            );
35
        } elseif (empty($this->xmlRepresentation)) {
36
            $this->markTestSkipped(
37
                'Unable to run ' . self::class . '::testSerialization(). Please set ' . self::class
38
                . ':$xmlRepresentation to a DOMDocument representing the XML-class being tested',
39
            );
40
        } else {
41
            /** @psalm-var \DOMElement */
42
            $xmlRepresentationDocument = $this->xmlRepresentation->documentElement;
43
            $this->assertEquals(
0 ignored issues
show
Bug introduced by
It seems like assertEquals() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
            $this->/** @scrutinizer ignore-call */ 
44
                   assertEquals(
Loading history...
44
                $this->xmlRepresentation->saveXML($xmlRepresentationDocument),
45
                strval(unserialize(serialize($this->testedClass::fromXML($xmlRepresentationDocument)))),
46
            );
47
        }
48
    }
49
}
50