Issues (33)

src/XML/TestUtils/ArrayizableElementTestTrait.php (5 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\TestUtils;
6
7
use PHPUnit\Framework\Attributes\Depends;
0 ignored issues
show
The type PHPUnit\Framework\Attributes\Depends 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
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 static string $testedClass;
20
21
    /** @var array */
22
    protected static array $arrayRepresentation;
23
24
25
    /**
26
     * Test arrayization / de-arrayization
27
     */
28
    #[Depends('testMarshalling')]
29
    public function testArrayization(): void
30
    {
31
        if (!class_exists(self::$testedClass)) {
32
            $this->markTestSkipped(
0 ignored issues
show
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

32
            $this->/** @scrutinizer ignore-call */ 
33
                   markTestSkipped(
Loading history...
33
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
34
                . ':$element to a class-string representing the XML-class being tested',
35
            );
36
        } elseif (self::$arrayRepresentation === null) {
0 ignored issues
show
The condition self::arrayRepresentation === null is always false.
Loading history...
37
            $this->markTestSkipped(
38
                'Unable to run ' . self::class . '::testArrayization(). Please set ' . self::class
39
                . ':$arrayRepresentation to an array representing the XML-class being tested',
40
            );
41
        } else {
42
            $this->assertEquals(
0 ignored issues
show
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

42
            $this->/** @scrutinizer ignore-call */ 
43
                   assertEquals(
Loading history...
43
                self::$arrayRepresentation,
44
                self::$testedClass::fromArray(self::$arrayRepresentation)->toArray(),
45
            );
46
        }
47
    }
48
}
49