Skip to content

Commit ccded1a

Browse files
committed
[Serializer] GetSetMethodNormalize: fix BC break with Ignore attribute
1 parent 2e73037 commit ccded1a

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function supports(string $class): bool
9797
private function isGetMethod(\ReflectionMethod $method): bool
9898
{
9999
return !$method->isStatic()
100-
&& !$method->getAttributes(Ignore::class)
100+
&& !$method->getAttributes(Ignore::class, \ReflectionAttribute::IS_INSTANCEOF)
101101
&& !$method->getNumberOfRequiredParameters()
102102
&& ((2 < ($methodLength = \strlen($method->name)) && str_starts_with($method->name, 'is'))
103103
|| (3 < $methodLength && (str_starts_with($method->name, 'has') || str_starts_with($method->name, 'get')))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Serializer\Tests\Fixtures\Attributes;
13+
14+
use Symfony\Component\Serializer\Annotation\Ignore;
15+
16+
class ClassWithIgnoreAnnotation
17+
{
18+
public string $foo;
19+
20+
#[Ignore]
21+
public function isSomeIgnoredMethod(): bool
22+
{
23+
return true;
24+
}
25+
}

src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
3131
use Symfony\Component\Serializer\Serializer;
3232
use Symfony\Component\Serializer\SerializerInterface;
33+
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAnnotation;
3334
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\ClassWithIgnoreAttribute;
3435
use Symfony\Component\Serializer\Tests\Fixtures\Attributes\GroupDummy;
3536
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
@@ -427,9 +428,22 @@ public function testNoStaticGetSetSupport()
427428
$this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
428429
}
429430

430-
public function testNotIgnoredMethodSupport()
431+
/**
432+
* @param class-string $class
433+
*
434+
* @dataProvider provideNotIgnoredMethodSupport
435+
*/
436+
public function testNotIgnoredMethodSupport(string $class)
431437
{
432-
$this->assertFalse($this->normalizer->supportsNormalization(new ClassWithIgnoreAttribute()));
438+
$this->assertFalse($this->normalizer->supportsNormalization(new $class()));
439+
}
440+
441+
public static function provideNotIgnoredMethodSupport(): iterable
442+
{
443+
return [
444+
[ClassWithIgnoreAttribute::class],
445+
[ClassWithIgnoreAnnotation::class],
446+
];
433447
}
434448

435449
public function testPrivateSetter()

0 commit comments

Comments
 (0)