diff --git a/CHANGELOG.md b/CHANGELOG.md index df3ba26e..fb264f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- UriRetriever: Include actual media type in InvalidSchemaMediaTypeException message ([#872](https://github.com/jsonrainbow/json-schema/pull/872)) ## [6.6.4] - 2025-12-19 ### Changed diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index 361512a9..8a6110d6 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -91,7 +91,7 @@ public function confirmMediaType($uriRetriever, $uri) } } - throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE)); + throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected, but %s given', Validator::SCHEMA_MEDIA_TYPE, $contentType)); } /** diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 4e791768..e14f2205 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -263,6 +263,20 @@ public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes(): void $retriever->confirmMediaType($uriRetriever, null); } + public function testConfirmMediaTypeExceptionIncludesActualMediaType(): void + { + $uriRetriever = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); + $retriever = new UriRetriever(); + $uriRetriever->expects($this->at(0)) + ->method('getContentType') + ->willReturn('text/html'); + + $this->expectException(InvalidSchemaMediaTypeException::class); + $this->expectExceptionMessage('Media type application/schema+json expected, but text/html given'); + + $retriever->confirmMediaType($uriRetriever, null); + } + private function mockRetriever($schema): void { $retrieverMock = $this->getRetrieverMock($schema);