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

[Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 #45981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ public function php81TypesProvider()
];
}

/**
* @dataProvider php82TypesProvider
* @requires PHP 8.2
*/
public function testExtractPhp82Type($property, array $type = null)
{
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, []));
}

public function php82TypesProvider()
{
yield ['nil', null];
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
}

/**
* @dataProvider defaultValueProvider
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved

class Php82Dummy
{
public null $nil = null;

public false $false = false;
}
2 changes: 2 additions & 0 deletions 2 src/Symfony/Component/PropertyInfo/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Type
public const BUILTIN_TYPE_OBJECT = 'object';
public const BUILTIN_TYPE_ARRAY = 'array';
public const BUILTIN_TYPE_NULL = 'null';
public const BUILTIN_TYPE_FALSE = 'false';
public const BUILTIN_TYPE_CALLABLE = 'callable';
public const BUILTIN_TYPE_ITERABLE = 'iterable';

Expand All @@ -45,6 +46,7 @@ class Type
self::BUILTIN_TYPE_OBJECT,
self::BUILTIN_TYPE_ARRAY,
self::BUILTIN_TYPE_CALLABLE,
self::BUILTIN_TYPE_FALSE,
self::BUILTIN_TYPE_NULL,
self::BUILTIN_TYPE_ITERABLE,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
return (float) $data;
}

if (('is_'.$builtinType)($data)) {
if ('false' === $builtinType || ('is_'.$builtinType)($data)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've inlined the value of the constant: the minimum version bump is not worth it IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, will do it as well for php/php-src#8326 when it's accepted. Thanks 👍

return $data;
}
} catch (NotNormalizableValueException $e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Serializer\Tests\Fixtures;
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved

class FalseBuiltInDummy
{
public false $false = false;
}
14 changes: 14 additions & 0 deletions 14 src/Symfony/Component/Serializer/Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
use Symfony\Component\Serializer\Tests\Fixtures\FalseBuiltInDummy;
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
Expand Down Expand Up @@ -572,6 +573,19 @@ public function testUnionTypeDeserializable()
$this->assertEquals(new DummyUnionType(), $actual, 'Union type denormalization third case failed.');
}

/**
* @requires PHP 8.2
*/
public function testFalseBuiltInTypes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case was triggering a warning: This test did not perform any assertions

I fixed it.

{
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);

$actual = $serializer->deserialize('{"false":false}', FalseBuiltInDummy::class, 'json');

$this->assertEquals(new FalseBuiltInDummy(), $actual);
}

private function serializerWithClassDiscriminator()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.