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
 * @phpstan-ignore trait.unused
16
 */
17
trait ArrayizableElementTestTrait
18
{
19
    /** @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...
20
    protected static string $testedClass;
21
22
    /** @var array */
23
    protected static array $arrayRepresentation;
24
25
26
    /**
27
     * Test arrayization / de-arrayization
28
     */
29
    #[Depends('testMarshalling')]
30
    public function testArrayization(): void
31
    {
32
        if (!class_exists(self::$testedClass)) {
33
            $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

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

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