Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ec0453

Browse filesBrowse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Serializer] Add support of true built-in type (from PHP 8.2)
1 parent 96a7485 commit 2ec0453
Copy full SHA for 2ec0453

File tree

5 files changed

+35
-1
lines changed
Filter options

5 files changed

+35
-1
lines changed

‎src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public function php82TypesProvider()
313313
{
314314
yield ['nil', null];
315315
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
316+
yield ['true', [new Type(Type::BUILTIN_TYPE_TRUE)]];
316317
}
317318

318319
/**

‎src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ class Php82Dummy
1616
public null $nil = null;
1717

1818
public false $false = false;
19+
20+
public true $true = true;
1921
}

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri
565565
return (float) $data;
566566
}
567567

568-
if (Type::BUILTIN_TYPE_FALSE === $builtinType && false === $data) {
568+
if ((Type::BUILTIN_TYPE_FALSE === $builtinType && false === $data) || (Type::BUILTIN_TYPE_TRUE === $builtinType && true === $data)) {
569569
return $data;
570570
}
571571

+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
class TrueBuiltInDummy
15+
{
16+
public true $true = true;
17+
}

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
6464
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
6565
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
66+
use Symfony\Component\Serializer\Tests\Fixtures\TrueBuiltInDummy;
6667
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
6768
use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer;
6869

@@ -795,6 +796,19 @@ public function testFalseBuiltInTypes()
795796
$this->assertEquals(new FalseBuiltInDummy(), $actual);
796797
}
797798

799+
/**
800+
* @requires PHP 8.2
801+
*/
802+
public function testTrueBuiltInTypes()
803+
{
804+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
805+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
806+
807+
$actual = $serializer->deserialize('{"true":true}', TrueBuiltInDummy::class, 'json');
808+
809+
$this->assertEquals(new TrueBuiltInDummy(), $actual);
810+
}
811+
798812
private function serializerWithClassDiscriminator()
799813
{
800814
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.