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 0608808

Browse filesBrowse files
[Serializer][PropertyInfo] Add support of true built-in type (from PHP 8.2)
1 parent 6e1675d commit 0608808
Copy full SHA for 0608808

File tree

6 files changed

+37
-3
lines changed
Filter options

6 files changed

+37
-3
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/PropertyInfo/Type.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Type.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Type
2828
public const BUILTIN_TYPE_OBJECT = 'object';
2929
public const BUILTIN_TYPE_ARRAY = 'array';
3030
public const BUILTIN_TYPE_NULL = 'null';
31-
public const BUILTIN_TYPE_FALSE = 'false';
3231
public const BUILTIN_TYPE_TRUE = 'true';
32+
public const BUILTIN_TYPE_FALSE = 'false';
3333
public const BUILTIN_TYPE_CALLABLE = 'callable';
3434
public const BUILTIN_TYPE_ITERABLE = 'iterable';
3535

@@ -47,8 +47,8 @@ class Type
4747
self::BUILTIN_TYPE_OBJECT,
4848
self::BUILTIN_TYPE_ARRAY,
4949
self::BUILTIN_TYPE_CALLABLE,
50-
self::BUILTIN_TYPE_FALSE,
5150
self::BUILTIN_TYPE_TRUE,
51+
self::BUILTIN_TYPE_FALSE,
5252
self::BUILTIN_TYPE_NULL,
5353
self::BUILTIN_TYPE_ITERABLE,
5454
];

‎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
@@ -564,7 +564,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri
564564
return (float) $data;
565565
}
566566

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

+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
@@ -61,6 +61,7 @@
6161
use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
6262
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
6363
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
64+
use Symfony\Component\Serializer\Tests\Fixtures\TrueBuiltInDummy;
6465
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
6566
use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer;
6667

@@ -764,6 +765,19 @@ public function testFalseBuiltInTypes()
764765
$this->assertEquals(new FalseBuiltInDummy(), $actual);
765766
}
766767

768+
/**
769+
* @requires PHP 8.2
770+
*/
771+
public function testTrueBuiltInTypes()
772+
{
773+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
774+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
775+
776+
$actual = $serializer->deserialize('{"true":true}', TrueBuiltInDummy::class, 'json');
777+
778+
$this->assertEquals(new TrueBuiltInDummy(), $actual);
779+
}
780+
767781
private function serializerWithClassDiscriminator()
768782
{
769783
$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.