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

ArrayizableElementTestTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A testArrayization() 0 23 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 arrayizable XML classes to perform default serialization tests.
13
 *
14
 * @package simplesamlphp\xml-common
15
 */
16
trait ArrayizableElementTestTrait
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 array */
22
    protected array $arrayRepresentation;
23
24
25
    /**
26
     * Test arrayization / de-arrayization
27
     */
28
    public function testArrayization(): void
29
    {
30
        /** @psalm-var class-string|null */
31
        $testedClass = $this->testedClass;
0 ignored issues
show
Unused Code introduced by
The assignment to $testedClass is dead and can be removed.
Loading history...
32
33
        /** @psalm-var array|null */
34
        $arrayRepresentation = $this->arrayRepresentation;
0 ignored issues
show
Unused Code introduced by
The assignment to $arrayRepresentation is dead and can be removed.
Loading history...
35
36
37
        if (!class_exists($this->testedClass)) {
38
            $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

38
            $this->/** @scrutinizer ignore-call */ 
39
                   markTestSkipped(
Loading history...
39
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
40
                . ':$element to a class-string representing the XML-class being tested',
41
            );
42
        } elseif ($this->arrayRepresentation === null) {
43
            $this->markTestSkipped(
44
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
45
                . ':$arrayRepresentation to an array representing the XML-class being tested',
46
            );
47
        } else {
48
            $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

48
            $this->/** @scrutinizer ignore-call */ 
49
                   assertEquals(
Loading history...
49
                $this->arrayRepresentation,
50
                $this->testedClass::fromArray($this->arrayRepresentation)->toArray(),
51
            );
52
        }
53
    }
54
}
55