Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 594ce46

Browse files
javernicolas-grekas
authored andcommitted
[PropertyInfo][Serializer] Fixed extracting ignored properties
1 parent c59dc2e commit 594ce46

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getProperties(string $class, array $context = []): ?array
4747
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);
4848

4949
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
50-
$ignored = method_exists($serializerClassMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored();
50+
$ignored = method_exists($serializerAttributeMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored();
5151
if (!$ignored && array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups())) {
5252
$properties[] = $serializerAttributeMetadata->getName();
5353
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
17+
use Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy;
18+
use Symfony\Component\Serializer\Annotation\Ignore;
1719
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1820
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
1921

@@ -40,4 +42,13 @@ public function testGetProperties()
4042
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', ['serializer_groups' => ['a']])
4143
);
4244
}
45+
46+
public function testGetPropertiesWithIgnoredProperties()
47+
{
48+
if (!class_exists(Ignore::class)) {
49+
$this->markTestSkipped('Ignore annotation is not implemented in current symfony/serializer version');
50+
}
51+
52+
$this->assertSame(['visibleProperty'], $this->extractor->getProperties(IgnorePropertyDummy::class, ['serializer_groups' => ['a']]));
53+
}
4354
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\PropertyInfo\Tests\Fixtures;
13+
14+
use Symfony\Component\Serializer\Annotation\Groups;
15+
use Symfony\Component\Serializer\Annotation\Ignore;
16+
17+
/**
18+
* @author Vadim Borodavko <[email protected]>
19+
*/
20+
class IgnorePropertyDummy
21+
{
22+
/**
23+
* @Groups({"a"})
24+
*/
25+
public $visibleProperty;
26+
27+
/**
28+
* @Groups({"a"})
29+
* @Ignore
30+
*/
31+
private $ignoredProperty;
32+
}

0 commit comments

Comments
 (0)