Skip to content

Commit

Permalink
Fix supports denormalization (#35)
Browse files Browse the repository at this point in the history
* Add test illustrating issue

* Return true for anything that implements UuidInterface

* Update CHANGELOG.md
  • Loading branch information
kalifg authored May 1, 2024
1 parent a9e0bd1 commit 87f804a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file based on the [Keep a Changelog](http://keepachangelog.com/) Standard.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/gbprod/uuid-normalizer/compare/v1.3.0...HEAD)

- Fix bug in supporting denormalization of classes implementing `UuidInterface` (#35)

## [v1.3.0](https://github.com/gbprod/uuid-normalizer/compare/v1.2.2...v1.3.0)

- Drop php `<7.4` and Symfony `<=5.4`
Expand Down
2 changes: 1 addition & 1 deletion src/UuidDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function denormalize($data, string $type, string $format = null, array $c
*/
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
{
return Uuid::class === $type || UuidInterface::class === $type;
return is_a($type, UuidInterface::class, true);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/UuidDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use GBProd\UuidNormalizer\UuidDenormalizer;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Rfc4122\UuidV1;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
Expand Down Expand Up @@ -93,4 +94,14 @@ public function testDenormalizeNull(): void
$this->denormalizer->denormalize(null, Uuid::class)
);
}

public function testSupportsIsTrueIfTypeImplementsUuidInterface(): void
{
$this->assertTrue(
$this->denormalizer->supportsDenormalization(
self::UUID_SAMPLE,
UuidV1::class
)
);
}
}

0 comments on commit 87f804a

Please sign in to comment.