Skip to content

Commit

Permalink
[ci skip] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mhujer committed Oct 30, 2021
1 parent 9c669d7 commit 5d91e18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Uuid/UuidSerializerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public static function getSubscribingMethods(): array
*/
public function deserializeUuid(DeserializationVisitorInterface $visitor, $data, array $type, Context $context): UuidInterface
{
// @todo need to bump min req to PHP 8.0 first
if (!is_scalar($data) && !$data instanceof \Stringable) {
// @todo custom exception
throw new \Exception('!');
}

try {
return $this->deserializeUuidValue((string) $data);
} catch (\Mhujer\JmsSerializer\Uuid\InvalidUuidException $e) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Uuid/UuidSerializerHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ public function testDeserializeInvalidUuid(): void
}
}

public function testDeserializeWithArrayInsteadOfIdThrows(): void
{
$serializer = $this->getSerializer();

try {
$serializer->deserialize('{
"id":{}
}', User::class, 'json');

$this->fail();

} catch (\Mhujer\JmsSerializer\Uuid\DeserializationInvalidValueException $e) {

$this->assertSame('id', $e->getFieldPath());
/** @var \Mhujer\JmsSerializer\Uuid\InvalidUuidException $previous */
$previous = $e->getPrevious();
$this->assertSame('86be949f-7f46-4457-9230-fad9783337xx', $previous->getInvalidUuid());
}
}

private function getSerializer(): SerializerInterface
{
return SerializerBuilder::create()
Expand Down

0 comments on commit 5d91e18

Please sign in to comment.