-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Uid normalizer * Install symfony/uid + Fix tests * Add php 7.2 limit on UUID tests + add test * Remove service if class doesn't exist * Remove php < 8 support + support php 8.3 * Revert symfony 7 support * Conflict with symfony/doctrine-bridge >= 7.0.0 --------- Co-authored-by: Jérémy Leherpeur <[email protected]>
- Loading branch information
Showing
7 changed files
with
70 additions
and
21 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
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
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer; | ||
use Symfony\Component\Serializer\Normalizer\UidNormalizer; | ||
|
||
/** | ||
* @author Kévin Dunglas <[email protected]> | ||
|
@@ -51,6 +52,10 @@ public function load(array $configs, ContainerBuilder $container): void | |
$container->removeDefinition('dunglas_doctrine_json_odm.normalizer.backed_enum'); | ||
} | ||
|
||
if (!class_exists(UidNormalizer::class)) { | ||
$container->removeDefinition('dunglas_doctrine_json_odm.normalizer.uid'); | ||
} | ||
|
||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
|
||
if ($config['type_map'] ?? []) { | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Product; | ||
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Enum\InputMode; | ||
use Symfony\Component\Console\Input\StringInput; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
/** | ||
* @author Kévin Dunglas <[email protected]> | ||
|
@@ -218,4 +219,31 @@ public function testStoreAndRetrieveEnum(): void | |
|
||
$this->assertSame(InputMode::EMAIL, $retrievedProduct->attributes[0]->value); | ||
} | ||
|
||
/** | ||
* @requires function \Symfony\Component\Serializer\Normalizer\UidNormalizer::normalize | ||
*/ | ||
public function testStoreAndRetrieveUid(): void | ||
{ | ||
$uuid = '1a87e1f2-1569-4493-a4a8-bc1915ca5631'; | ||
|
||
$attribute = new Attribute(); | ||
$attribute->key = 'uid'; | ||
$attribute->value = Uuid::fromString($uuid); | ||
|
||
$product = new Product(); | ||
$product->name = 'My product'; | ||
$product->attributes = [$attribute]; | ||
|
||
$manager = self::$kernel->getContainer()->get('doctrine')->getManagerForClass(Product::class); | ||
$manager->persist($product); | ||
$manager->flush(); | ||
|
||
$manager->clear(); | ||
|
||
$retrievedProduct = $manager->find(Product::class, $product->id); | ||
|
||
$this->assertInstanceOf(Uuid::class, $retrievedProduct->attributes[0]->value); | ||
$this->assertEquals($uuid, (string) $retrievedProduct->attributes[0]->value); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Document\WithMappedType; | ||
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Foo; | ||
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Enum\InputMode; | ||
use Symfony\Component\Uid\UuidV4; | ||
|
||
/** | ||
* @author Kévin Dunglas <[email protected]> | ||
|
@@ -223,4 +224,21 @@ public function testSerializeEnum(): void | |
|
||
$this->assertEquals($value, $restoredValue); | ||
} | ||
|
||
/** | ||
* @requires function \Symfony\Component\Serializer\Normalizer\UidNormalizer::normalize | ||
*/ | ||
public function testSerializeUid(): void | ||
{ | ||
$serializer = self::$kernel->getContainer()->get('dunglas_doctrine_json_odm.serializer'); | ||
|
||
$value = new UuidV4('4a7ba820-c806-4579-a907-193a2493863b'); | ||
$data = $serializer->serialize($value, 'json'); | ||
$decodeData = json_decode($data, true); | ||
$this->assertArrayHasKey('#type', $decodeData); | ||
$this->assertSame(UuidV4::class, $decodeData['#type']); | ||
$restoredValue = $serializer->deserialize($data, '', 'json'); | ||
|
||
$this->assertEquals($value, $restoredValue); | ||
} | ||
} |