-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow UuidInterface array deserialization
This commit will allow deserialization of array of UuidInterface using PhpDocExtractor. Ref: #12
- Loading branch information
Showing
8 changed files
with
274 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
# Change Log | ||
|
||
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.1.0...HEAD) | ||
## [Unreleased](https://github.com/gbprod/uuid-normalizer/compare/v1.2.0...HEAD) | ||
|
||
- Fix array of UuidInterface deserialization (#12) | ||
|
||
## [Unreleased](https://github.com/gbprod/uuid-normalizer/compare/v1.1.0...v1.2.0) | ||
|
||
- Changing licence | ||
- Update dependencies to php 8, Symfony 5 and Ramsey Uuid 4 | ||
- Changing licence | ||
|
||
## [v1.1.0](https://github.com/gbprod/uuid-normalizer/compare/v1.0.1...v1.1.0) | ||
- Symfony 4 compatibility | ||
- Add Contributing file | ||
- Drop php 5.5 compatibility | ||
|
||
- Symfony 4 compatibility | ||
- Add Contributing file | ||
- Drop php 5.5 compatibility | ||
|
||
## [v1.0.0](https://github.com/gbprod/uuid-normalizer/compare/v1.0.0...v1.0.1) | ||
|
||
### Added | ||
|
||
- Version eye badge | ||
- Changelog | ||
- Compatibility and tests for Symfony Serializer 3.1 and Ramsey/Uuid 3.3 and 3.4 | ||
- More examples in documentation | ||
|
||
### Changed | ||
|
||
- Scrutinizer use PSR2 codesniffer | ||
- Use codecov instead of scrutinizer for coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
{ | ||
"name": "gbprod/uuid-normalizer", | ||
"description": "Normalizer to serialize Ramsey Uuid with Symfony Serializer", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"GBProd\\UuidNormalizer\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\GBProd\\UuidNormalizer\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^5.6|^7.0|^8.0", | ||
"ramsey/uuid": "^3.0|^4.0", | ||
"symfony/serializer": "^2.3|^3.0|^4.0|^5.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7|^6.0" | ||
}, | ||
"license": "WTFPL", | ||
"authors": [ | ||
{ | ||
"name": "GBProd", | ||
"email": "[email protected]" | ||
} | ||
] | ||
"name": "gbprod/uuid-normalizer", | ||
"description": "Normalizer to serialize Ramsey Uuid with Symfony Serializer", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"GBProd\\UuidNormalizer\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\GBProd\\UuidNormalizer\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^5.6|^7.0|^8.0", | ||
"ramsey/uuid": "^3.0|^4.0", | ||
"symfony/serializer": "^2.3|^3.0|^4.0|^5.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7|^6.0", | ||
"symfony/property-access": "^2.3|^3.0|^4.0|^5.0" | ||
}, | ||
"license": "WTFPL", | ||
"authors": [ | ||
{ | ||
"name": "GBProd", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ public function supportsNormalization($data, $format = null) | |
{ | ||
return $data instanceof UuidInterface; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
namespace Tests\GBProd\UuidNormalizer; | ||
|
||
use GBProd\UuidNormalizer\UuidDenormalizer; | ||
use GBProd\UuidNormalizer\UuidNormalizer; | ||
use PHPUnit\Framework\TestCase; | ||
use Ramsey\Uuid\Uuid; | ||
use Ramsey\Uuid\UuidInterface; | ||
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; | ||
use Symfony\Component\Serializer\Encoder\JsonEncoder; | ||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
use Symfony\Component\Serializer\Serializer; | ||
|
||
class DenormalizeUsingPhpDocTest extends TestCase | ||
{ | ||
private $serializer; | ||
|
||
public function setUp() | ||
{ | ||
$normalizers = [ | ||
new UuidNormalizer(), | ||
new UuidDenormalizer(), | ||
new ObjectNormalizer( | ||
null, | ||
null, | ||
null, | ||
class_exists('Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor') ? new PhpDocExtractor() : null | ||
) | ||
]; | ||
|
||
if (class_exists('Symfony\Component\Serializer\Normalizer\ArrayDenormalizer')) { | ||
$normalizers[] = new ArrayDenormalizer(); | ||
} | ||
|
||
$this->serializer = new Serializer($normalizers, [ | ||
new JsonEncoder(), | ||
]); | ||
} | ||
|
||
public function testDenormalizeWithUuid() | ||
{ | ||
$uuid = Uuid::uuid4(); | ||
$denormalized = $this->serializer->denormalize( | ||
['uuid' => $uuid->toString()], | ||
ClassWithUuidAttribute::class | ||
); | ||
|
||
$this->assertEquals($uuid, $denormalized->uuid); | ||
} | ||
|
||
public function testDenormalizeWithUuidInterface() | ||
{ | ||
$uuid = Uuid::uuid4(); | ||
$denormalized = $this->serializer->denormalize( | ||
['uuid' => $uuid->toString()], | ||
ClassWithUuidInterfaceAttribute::class | ||
); | ||
|
||
$this->assertEquals($uuid, $denormalized->uuid); | ||
} | ||
|
||
public function testDenormalizeWithArrayOfUuid() | ||
{ | ||
$uuids = [ | ||
Uuid::uuid1(), | ||
Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net'), | ||
Uuid::uuid4(), | ||
Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net'), | ||
]; | ||
|
||
$denormalized = $this->serializer->denormalize( | ||
['uuids' => array_map(function ($uuid) { | ||
return $uuid->toString(); | ||
}, $uuids)], | ||
ClassWithArrayOfUuidAttribute::class | ||
); | ||
|
||
$this->assertEquals($uuids, $denormalized->uuids); | ||
} | ||
|
||
public function testDenormalizeWithArrayOfUuidInterface() | ||
{ | ||
$uuids = [ | ||
Uuid::uuid1(), | ||
Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net'), | ||
Uuid::uuid4(), | ||
Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net'), | ||
]; | ||
|
||
$denormalized = $this->serializer->denormalize( | ||
['uuids' => array_map(function ($uuid) { | ||
return $uuid->toString(); | ||
}, $uuids)], | ||
ClassWithArrayOfUuidInterfaceAttribute::class | ||
); | ||
|
||
$this->assertEquals($uuids, $denormalized->uuids); | ||
} | ||
} | ||
|
||
class ClassWithUuidAttribute | ||
{ | ||
/** @var Uuid */ | ||
public $uuid; | ||
} | ||
|
||
class ClassWithUuidInterfaceAttribute | ||
{ | ||
/** @var UuidInterface */ | ||
public $uuid; | ||
} | ||
|
||
|
||
class ClassWithArrayOfUuidAttribute | ||
{ | ||
/** @var Uuid[] */ | ||
public $uuids; | ||
} | ||
|
||
class ClassWithArrayOfUuidInterfaceAttribute | ||
{ | ||
/** @var UuidInterface[] */ | ||
public $uuids; | ||
} |
Oops, something went wrong.