Passed
Branch master (a3c4c5)
by Tim
02:38 queued 53s
created

ArrayizableElementTestTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\TestUtils;
6
7
use function class_exists;
8
9
/**
10
 * Test for arrayizable XML classes to perform default serialization tests.
11
 *
12
 * @package simplesamlphp\xml-common
13
 */
14
trait ArrayizableElementTestTrait
15
{
16
    /** @var class-string */
17
    protected static string $testedClass;
18
19
    /** @var array */
20
    protected static array $arrayRepresentation;
21
22
23
    /**
24
     * Test arrayization / de-arrayization
25
     */
26
    public function testArrayization(): void
27
    {
28
        if (!class_exists(self::$testedClass)) {
29
            $this->markTestSkipped(
30
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
31
                . ':$element to a class-string representing the XML-class being tested',
32
            );
33
        } elseif (self::$arrayRepresentation === null) {
34
            $this->markTestSkipped(
35
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
36
                . ':$arrayRepresentation to an array representing the XML-class being tested',
37
            );
38
        } else {
39
            $this->assertEquals(
40
                self::$arrayRepresentation,
41
                self::$testedClass::fromArray(self::$arrayRepresentation)->toArray(),
42
            );
43
        }
44
    }
45
}
46