Skip to content

Commit

Permalink
fixup! 10a4ddc
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 11, 2023
1 parent e585d31 commit bc40f96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/Codec/CodecLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
19 changes: 10 additions & 9 deletions tests/Codec/CodecLibraryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit bc40f96

Please sign in to comment.