Skip to content

Commit

Permalink
Revert "Serializer: Support ignore annotation (api-platform#3820)"
Browse files Browse the repository at this point in the history
This reverts commit 347a095.
  • Loading branch information
meyerbaptiste committed Dec 18, 2020
1 parent 75deb1a commit 85fb81c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 78 deletions.
11 changes: 0 additions & 11 deletions src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,8 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
$options = $this->getFactoryOptions($context);
$propertyNames = $this->propertyNameCollectionFactory->create($context['resource_class'], $options);

$attributesMetadata = $this->classMetadataFactory ?
$this->classMetadataFactory->getMetadataFor($context['resource_class'])->getAttributesMetadata() :
null;

$allowedAttributes = [];
foreach ($propertyNames as $propertyName) {
if (
null != $attributesMetadata && \array_key_exists($propertyName, $attributesMetadata) &&
method_exists($attributesMetadata[$propertyName], 'isIgnored') &&
$attributesMetadata[$propertyName]->isIgnored()) {
continue;
}

$propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $propertyName, $options);

if (
Expand Down
67 changes: 0 additions & 67 deletions tests/Serializer/AbstractItemNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
Expand Down Expand Up @@ -1205,68 +1202,4 @@ public function testNormalizationWithDataTransformer()

$propertyAccessorProphecy->setValue($actualDummy, 'name', 'Dummy')->shouldHaveBeenCalled();
}

public function testNormalizationWithIgnoreMetadata()
{
if (!method_exists(AttributeMetadata::class, 'setIgnore')) {
$this->markTestSkipped();
}

$dummy = new Dummy();

$dummyAttributeMetadata = new AttributeMetadata('dummy');
$dummyAttributeMetadata->setIgnore(true);

$classMetadataProphecy = $this->prophesize(ClassMetadataInterface::class);
$classMetadataProphecy->getAttributesMetadata()->willReturn(['dummy' => $dummyAttributeMetadata]);

$classMetadataFactoryProphecy = $this->prophesize(ClassMetadataFactoryInterface::class);
$classMetadataFactoryProphecy->getMetadataFor(Dummy::class)->willReturn($classMetadataProphecy->reveal());

$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$propertyNameCollectionFactoryProphecy->create(Dummy::class, [])->willReturn(new PropertyNameCollection(['name', 'dummy']));

$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING), '', true));
$propertyMetadataFactoryProphecy->create(Dummy::class, 'dummy', [])->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING), '', true));

$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummies/1');

$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
$propertyAccessorProphecy->getValue($dummy, 'name')->willReturn('foo');
$propertyAccessorProphecy->getValue($dummy, 'dummy')->willReturn('bar');

$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->getResourceClass($dummy, null)->willReturn(Dummy::class);

$serializerProphecy = $this->prophesize(SerializerInterface::class);
$serializerProphecy->willImplement(NormalizerInterface::class);
$serializerProphecy->normalize('foo', null, Argument::type('array'))->willReturn('foo');
$serializerProphecy->normalize('bar', null, Argument::type('array'))->willReturn('bar');

$normalizer = $this->getMockForAbstractClass(AbstractItemNormalizer::class, [
$propertyNameCollectionFactoryProphecy->reveal(),
$propertyMetadataFactoryProphecy->reveal(),
$iriConverterProphecy->reveal(),
$resourceClassResolverProphecy->reveal(),
$propertyAccessorProphecy->reveal(),
null,
$classMetadataFactoryProphecy->reveal(),
null,
false,
[],
[],
null,
null,
]);
$normalizer->setSerializer($serializerProphecy->reveal());

$expected = [
'name' => 'foo',
];
$this->assertEquals($expected, $normalizer->normalize($dummy, null, [
'resources' => [],
]));
}
}

0 comments on commit 85fb81c

Please sign in to comment.