Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0: (23 commits)
  [Serializer] Fix anonymous test class
  [Translation] Improve tests coverage
  [Routing] Add redirection.io as sponsor of versions 6.4/7.0/7.1
  don't check parameter values if they are not set
  [HttpClient] Add Innovative Web AG (i-web) as sponsor of version 6.4/7.0
  [Serializer] Fix normalization relying on allowed attributes only
  Minor @var doc update
  [Translation] Remove `@internal` from abstract testcases
  [VarExporter] Work around php/php-src#12695 for lazy objects, fixing nullsafe-related behavior
  [Validator] Add missing translations for Bulgarian #51931
  [VarExporter] Fix serializing objects that implement __sleep() and that are made lazy
  remove not needed method existance check
  fix typo
  fix typo
  Document BC break with $secret parameter introduction
  Bump Symfony version to 7.0.0
  Update VERSION for 7.0.0-RC2
  Update CHANGELOG for 7.0.0-RC2
  Bump Symfony version to 6.4.0
  Update VERSION for 6.4.0-RC2
  ...
  • Loading branch information
nicolas-grekas committed Nov 29, 2023
2 parents 1a0e5c1 + ac73ab2 commit b91da50
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Normalizer/AbstractObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected function getAttributes(object $object, ?string $format, array $context
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);

if (false !== $allowedAttributes) {
$attributes = array_intersect($attributes, $allowedAttributes);
$attributes = $attributes ? array_intersect($attributes, $allowedAttributes) : $allowedAttributes;
}

if ($context['cache_key'] && \stdClass::class !== $class) {
Expand Down
34 changes: 32 additions & 2 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,39 @@ public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
public function testNormalizeWithIgnoreAttributeAndPrivateProperties()
{
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$serializer = new Serializer([new ObjectNormalizer($classMetadataFactory)]);
$normalizer = new ObjectNormalizer($classMetadataFactory);

$this->assertSame(['foo' => 'foo'], $serializer->normalize(new ObjectDummyWithIgnoreAttributeAndPrivateProperty()));
$this->assertSame(['foo' => 'foo'], $normalizer->normalize(new ObjectDummyWithIgnoreAttributeAndPrivateProperty()));
}

public function testNormalizeBasedOnAllowedAttributes()
{
$normalizer = new class() extends AbstractObjectNormalizer {
protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false): array
{
return ['foo'];
}

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 $object->$attribute;
}

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

$object = new Dummy();
$object->foo = 'foo';
$object->bar = 'bar';

$this->assertSame(['foo' => 'foo'], $normalizer->normalize($object));
}

public function testDenormalizeUntypedFormat()
Expand Down

0 comments on commit b91da50

Please sign in to comment.