diff --git a/src/Codec/CodecLibrary.php b/src/Codec/CodecLibrary.php index 8ae23f16e..581f8e8ea 100644 --- a/src/Codec/CodecLibrary.php +++ b/src/Codec/CodecLibrary.php @@ -3,10 +3,8 @@ namespace MongoDB\Codec; use MongoDB\Exception\InvalidArgumentException; -use MongoDB\Exception\UnexpectedValueException; - -use function get_debug_type; -use function sprintf; +use MongoDB\Exception\UndecodableValueException; +use MongoDB\Exception\UnencodableValueException; class CodecLibrary implements Codec { @@ -114,7 +112,7 @@ final public function decode($value) } } - throw new UnexpectedValueException(sprintf('No decoder found for value of type "%s"', get_debug_type($value))); + throw new UndecodableValueException($value); } /** @@ -129,6 +127,6 @@ final public function encode($value) } } - throw new UnexpectedValueException(sprintf('No encoder found for value of type "%s"', get_debug_type($value))); + throw new UnencodableValueException($value); } } diff --git a/tests/Codec/CodecLibraryTest.php b/tests/Codec/CodecLibraryTest.php index 6fd1643f6..a2ea268ee 100644 --- a/tests/Codec/CodecLibraryTest.php +++ b/tests/Codec/CodecLibraryTest.php @@ -7,7 +7,8 @@ use MongoDB\Codec\DecodeIfSupported; use MongoDB\Codec\EncodeIfSupported; use MongoDB\Codec\KnowsCodecLibrary; -use MongoDB\Exception\UnexpectedValueException; +use MongoDB\Exception\UndecodableValueException; +use MongoDB\Exception\UnencodableValueException; use MongoDB\Tests\TestCase; class CodecLibraryTest extends TestCase @@ -36,16 +37,16 @@ public function testDecodeNull(): void $this->assertFalse($codec->canDecode(null)); - $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('No decoder found for value of type "null"'); + $this->expectException(UndecodableValueException::class); + $this->expectExceptionMessage('Could not decode value of type "null"'); $this->assertNull($codec->decode(null)); } public function testDecodeUnsupportedValue(): void { - $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('No decoder found for value of type "string"'); + $this->expectException(UndecodableValueException::class); + $this->expectExceptionMessage('Could not decode value of type "string"'); $this->getCodecLibrary()->decode('foo'); } @@ -74,16 +75,16 @@ public function testEncodeNull(): void $this->assertFalse($codec->canEncode(null)); - $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('No encoder found for value of type "null"'); + $this->expectException(UnencodableValueException::class); + $this->expectExceptionMessage('Could not encode value of type "null"'); $codec->encode(null); } public function testEncodeUnsupportedValue(): void { - $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('No encoder found for value of type "string"'); + $this->expectException(UnencodableValueException::class); + $this->expectExceptionMessage('Could not encode value of type "string"'); $this->getCodecLibrary()->encode('foo'); }