|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XML\TestUtils; |
|
6
|
|
|
|
|
7
|
|
|
use DOMDocument; |
|
8
|
|
|
use PHPUnit\Framework\Attributes\Depends; |
|
|
|
|
|
|
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
10
|
|
|
|
|
11
|
|
|
use function class_exists; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Test for AbstractElement classes to perform schema validation tests. |
|
15
|
|
|
* |
|
16
|
|
|
* @package simplesamlphp\xml-common |
|
17
|
|
|
* @phpstan-ignore trait.unused |
|
18
|
|
|
*/ |
|
19
|
|
|
trait SchemaValidationTestTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string|null */ |
|
22
|
|
|
protected static ?string $schemaFile = null; |
|
23
|
|
|
|
|
24
|
|
|
/** @var class-string */ |
|
|
|
|
|
|
25
|
|
|
protected static string $testedClass; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \DOMDocument */ |
|
28
|
|
|
protected static DOMDocument $xmlRepresentation; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test schema validation. |
|
33
|
|
|
*/ |
|
34
|
|
|
#[Depends('testSerialization')] |
|
35
|
|
|
public function testSchemaValidation(): void |
|
36
|
|
|
{ |
|
37
|
|
|
if (!class_exists(self::$testedClass)) { |
|
38
|
|
|
$this->markTestSkipped( |
|
|
|
|
|
|
39
|
|
|
'Unable to run ' . self::class . '::testSchemaValidation(). Please set ' . self::class |
|
40
|
|
|
. ':$testedClass to a class-string representing the XML-class being tested', |
|
41
|
|
|
); |
|
42
|
|
|
} elseif (empty(self::$xmlRepresentation)) { |
|
43
|
|
|
$this->markTestSkipped( |
|
44
|
|
|
'Unable to run ' . self::class . '::testSchemaValidation(). Please set ' . self::class |
|
45
|
|
|
. ':$xmlRepresentation to a DOMDocument representing the XML-class being tested', |
|
46
|
|
|
); |
|
47
|
|
|
} else { |
|
48
|
|
|
// Validate before serialization |
|
49
|
|
|
self::$testedClass::schemaValidate(self::$xmlRepresentation, self::$schemaFile); |
|
50
|
|
|
|
|
51
|
|
|
// Perform serialization |
|
52
|
|
|
$class = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement); |
|
53
|
|
|
$serializedClass = $class->toXML(); |
|
54
|
|
|
|
|
55
|
|
|
// Validate after serialization |
|
56
|
|
|
self::$testedClass::schemaValidate($serializedClass->ownerDocument, self::$schemaFile); |
|
57
|
|
|
|
|
58
|
|
|
// Validate after normalization |
|
59
|
|
|
if (self::$testedClass::getNormalization() === true) { |
|
60
|
|
|
$normalizedDoc = DOMDocumentFactory::normalizeDocument($serializedClass->ownerDocument); |
|
61
|
|
|
self::$testedClass::schemaValidate($normalizedDoc, self::$schemaFile); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// If we got this far and no exceptions were thrown, consider this test passed! |
|
65
|
|
|
$this->addToAssertionCount(1); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
abstract public function testSerialization(): void; |
|
71
|
|
|
} |
|
72
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths