Skip to content

[Serializer] Fixed "Warning: Attempt to read property "value" on string" #54851

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
Changes from 1 commit
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
Prev Previous commit
add test
  • Loading branch information
xabbuh committed May 17, 2024
commit 90251c9361b36543eb7c4ee1c4b8a5bd69de17b7
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,24 @@ public function testNormalizationWithMaxDepthOnStdclassObjectDoesNotThrowWarning

$this->assertSame(['string' => 'yes'], $normalized);
}

public function testDenormalizeCollectionOfScalarTypesPropertyWithPhpDocExtractor()
{
$normalizer = new AbstractObjectNormalizerWithMetadataAndPhpDocExtractor();
$data = [
'type' => 'foo',
'values' => [
['1'],
['2'],
['3'],
['4'],
['5'],
],
];
$expected = new ScalarCollectionDocBlockDummy([[1], [2], [3], [4], [5]]);

$this->assertEquals($expected, $normalizer->denormalize($data, ScalarCollectionDocBlockDummy::class));
}
}

class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
Expand Down Expand Up @@ -1540,3 +1558,50 @@ public function __construct(
) {
}
}

#[DiscriminatorMap('type', ['foo' => ScalarCollectionDocBlockDummy::class])]
class ScalarCollectionDocBlockDummy
{
/**
* @param array<int, array<int, string>>|null $values
*/
public function __construct(
private readonly ?array $values = null,
) {
}

/** @return array<int, array<int, string>>|null */
public function getValues(): ?array
{
return $this->values;
}
}

class AbstractObjectNormalizerWithMetadataAndPhpDocExtractor extends AbstractObjectNormalizer
{
public function __construct()
{
parent::__construct(new ClassMetadataFactory(new AttributeLoader()), null, new PropertyInfoExtractor([], [new PhpDocExtractor()]));
}

protected function extractAttributes(object $object, ?string $format = null, array $context = []): array
{
return [];
}

protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []): mixed
{
return null;
}

protected function setAttributeValue(object $object, string $attribute, mixed $value, ?string $format = null, array $context = []): void
{
}

public function getSupportedTypes(?string $format): array
{
return [
'*' => false,
];
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy