Issues (33)

src/XML/TestUtils/SchemaValidationTestTrait.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\TestUtils;
6
7
use DOMDocument;
8
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...
9
10
use function class_exists;
11
12
/**
13
 * Test for AbstractElement classes to perform schema validation tests.
14
 *
15
 * @package simplesamlphp\xml-common
16
 */
17
trait SchemaValidationTestTrait
18
{
19
    /** @var string|null */
20
    protected static ?string $schemaFile = null;
21
22
    /** @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...
23
    protected static string $testedClass;
24
25
    /** @var \DOMDocument */
26
    protected static DOMDocument $xmlRepresentation;
27
28
29
    /**
30
     * Test schema validation.
31
     */
32
    #[Depends('testSerialization')]
33
    public function testSchemaValidation(): void
34
    {
35
        if (!class_exists(self::$testedClass)) {
36
            $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

36
            $this->/** @scrutinizer ignore-call */ 
37
                   markTestSkipped(
Loading history...
37
                'Unable to run ' . self::class . '::testSchemaValidation(). Please set ' . self::class
38
                . ':$testedClass to a class-string representing the XML-class being tested',
39
            );
40
        } elseif (empty(self::$xmlRepresentation)) {
41
            $this->markTestSkipped(
42
                'Unable to run ' . self::class . '::testSchemaValidation(). Please set ' . self::class
43
                . ':$xmlRepresentation to a DOMDocument representing the XML-class being tested',
44
            );
45
        } else {
46
            // Validate before serialization
47
            self::$testedClass::schemaValidate(self::$xmlRepresentation, self::$schemaFile);
48
49
            // Perform serialization
50
            $class = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement);
51
            $serializedClass = $class->toXML();
52
53
            // Validate after serialization
54
            self::$testedClass::schemaValidate($serializedClass->ownerDocument, self::$schemaFile);
55
56
            // If we got this far and no exceptions were thrown, consider this test passed!
57
            $this->addToAssertionCount(1);
0 ignored issues
show
It seems like addToAssertionCount() 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

57
            $this->/** @scrutinizer ignore-call */ 
58
                   addToAssertionCount(1);
Loading history...
58
        }
59
    }
60
61
    abstract public function testSerialization(): void;
62
}
63