8000 bug #53414 [Serializer] `GetSetMethodNormalizer`: fix BC break with `… · symfony/symfony@635afca · GitHub
[go: up one dir, main page]

Skip to content

Commit 635afca

Browse files
bug #53414 [Serializer] GetSetMethodNormalizer: fix BC break with #[Ignore] attribute (nikophil)
This PR was merged into the 6.4 branch. Discussion ---------- [Serializer] `GetSetMethodNormalizer`: fix BC break with `#[Ignore]` attribute | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT This PR fixes a subtle BC break introduced by https://github.com/symfony/symfony/pull/52294/files: `GetSetMethodNormalizer` no more ignores methods marked as `#[Ignore]` with the old class `Symfony\Component\Serializer\Annotation\Ignore` Commits ------- ab42c55 [Serializer] GetSetMethodNormalize: fix BC break with Ignore attribute
2 parents cb1aaf5 + ab42c55 commit 635afca

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Serializer\Normalizer;
1313

14+
use Symfony\Component\Serializer\Annotation\Ignore as LegacyIgnore;
1415
use Symfony\Component\Serializer\Attribute\Ignore;
1516

1617
/**
@@ -97,7 +98,7 @@ private function supports(string $class): bool
9798
private function isGetMethod(\ReflectionMethod $method): bool
9899
{
99100
return !$method->isStatic()
100-
&& !$method->getAttributes(Ignore::class)
101+
&& !($method->getAttributes(Ignore::class) || $method->getAttributes(LegacyIgnore::class))
101102
&& !$method->getNumberOfRequiredParameters()
102103
&& ((2 < ($methodLength = \strlen($method->name)) && str_starts_with($method->name, 'is'))
103104
|| (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)

Footer

© 2025 GitHub, Inc.
0