From 7d7dc3d21d66fc69c2ee79cee29210181f1f2433 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sat, 14 Dec 2024 13:15:38 +0100 Subject: [PATCH] Slightly raise coverage --- tests/XML/DOMDocumentFactoryTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/XML/DOMDocumentFactoryTest.php b/tests/XML/DOMDocumentFactoryTest.php index 9b8636b..03c587f 100644 --- a/tests/XML/DOMDocumentFactoryTest.php +++ b/tests/XML/DOMDocumentFactoryTest.php @@ -5,6 +5,7 @@ namespace SimpleSAML\Test\XML; use DOMDocument; +use Exception; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; @@ -14,6 +15,8 @@ use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Exception\UnparseableXMLException; +use function restore_error_handler; +use function set_error_handler; use function strval; /** @@ -135,4 +138,20 @@ public function testSchemaValidationWrongElementFails(): void $this->expectException(SchemaViolationException::class); DOMDocumentFactory::fromFile($file, $schemaFile); } + + + public function testSchemaValidationUnknownSchemaFileFails(): void + { + $file = 'tests/resources/xml/ssp_Chunk.xml'; + $schemaFile = 'tests/resources/schemas/doesnotexist.xsd'; + + // Dirty trick to catch the warning emitted by PHP + set_error_handler(static function (int $errno, string $errstr): never { + restore_error_handler(); + throw new Exception($errstr, $errno); + }, E_WARNING); + + $this->expectExceptionMessage('Failed to locate the main schema resource at'); + DOMDocumentFactory::fromFile($file, $schemaFile); + } }