Skip to content

Commit

Permalink
Allow overriding the schema for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 19, 2024
1 parent e8eba9d commit 86f52b3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/TestUtils/SchemaValidationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
trait SchemaValidationTestTrait
{
/** @var string|null */
protected static ?string $schemaFile = null;

/** @var class-string */
protected static string $testedClass;

Expand All @@ -41,14 +44,14 @@ public function testSchemaValidation(): void
);
} else {
// Validate before serialization
self::$testedClass::schemaValidate(self::$xmlRepresentation);
self::$testedClass::schemaValidate(self::$xmlRepresentation, self::$schemaFile);

// Perform serialization
$class = self::$testedClass::fromXML(self::$xmlRepresentation->documentElement);
$serializedClass = $class->toXML();

// Validate after serialization
self::$testedClass::schemaValidate($serializedClass->ownerDocument);
self::$testedClass::schemaValidate($serializedClass->ownerDocument, self::$schemaFile);

// If we got this far and no exceptions were thrown, consider this test passed!
$this->addToAssertionCount(1);
Expand Down

0 comments on commit 86f52b3

Please sign in to comment.