Skip to content

Commit fdcbb53

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Serializer] Fix `GetSetMethodNormalizer` not working with setters with optional args [Cache] Fix support for predis/predis:^2.0
2 parents bb28f4c + 93f4f13 commit fdcbb53

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function isSetMethod(\ReflectionMethod $method): bool
9999
{
100100
return !$method->isStatic()
101101
&& !$method->getAttributes(Ignore::class)
102-
&& 1 === $method->getNumberOfRequiredParameters()
102+
&& 0 < $method->getNumberOfParameters()
103103
&& str_starts_with($method->name, 'set');
104104
}
105105

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,18 @@ public function testSupportsAndDenormalizeWithOnlyParentSetter()
543543
$obj = $this->normalizer->denormalize(['foo' => 'foo'], GetSetDummyChild::class);
544544
$this->assertSame('foo', $obj->getFoo());
545545
}
546+
547+
/**
548+
* @testWith [{"foo":"foo"}, "getFoo", "foo"]
549+
* [{"bar":"bar"}, "getBar", "bar"]
550+
*/
551+
public function testSupportsAndDenormalizeWithOptionalSetterArgument(array $data, string $method, string $expected)
552+
{
553+
$this->assertTrue($this->normalizer->supportsDenormalization($data, GetSetDummyWithOptionalAndMultipleSetterArgs::class));
554+
555+
$obj = $this->normalizer->denormalize($data, GetSetDummyWithOptionalAndMultipleSetterArgs::class);
556+
$this->assertSame($expected, $obj->$method());
557+
}
546558
}
547559

548560
class GetSetDummy
@@ -864,3 +876,29 @@ public function setFoo($foo)
864876
$this->foo = $foo;
865877
}
866878
}
879+
880+
class GetSetDummyWithOptionalAndMultipleSetterArgs
881+
{
882+
private $foo;
883+
private $bar;
884+
885+
public function getFoo()
886+
{
887+
return $this->foo;
888+
}
889+
890+
public function setFoo($foo = null)
891+
{
892+
$this->foo = $foo;
893+
}
894+
895+
public function getBar()
896+
{
897+
return $this->bar;
898+
}
899+
900+
public function setBar($bar = null, $other = true)
901+
{
902+
$this->bar = $bar;
903+
}
904+
}

0 commit comments

Comments
 (0)