Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  [Serializer] Fix `GetSetMethodNormalizer` not working with setters with optional args
  [Cache] Fix support for predis/predis:^2.0
  • Loading branch information
derrabus committed May 2, 2024
2 parents 820382c + fdcbb53 commit 616c582
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function isSetMethod(\ReflectionMethod $method): bool
{
return !$method->isStatic()
&& !$method->getAttributes(Ignore::class)
&& 1 === $method->getNumberOfRequiredParameters()
&& 0 < $method->getNumberOfParameters()
&& str_starts_with($method->name, 'set');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ public function testSupportsAndDenormalizeWithOnlyParentSetter()
$obj = $this->normalizer->denormalize(['foo' => 'foo'], GetSetDummyChild::class);
$this->assertSame('foo', $obj->getFoo());
}

/**
* @testWith [{"foo":"foo"}, "getFoo", "foo"]
* [{"bar":"bar"}, "getBar", "bar"]
*/
public function testSupportsAndDenormalizeWithOptionalSetterArgument(array $data, string $method, string $expected)
{
$this->assertTrue($this->normalizer->supportsDenormalization($data, GetSetDummyWithOptionalAndMultipleSetterArgs::class));

$obj = $this->normalizer->denormalize($data, GetSetDummyWithOptionalAndMultipleSetterArgs::class);
$this->assertSame($expected, $obj->$method());
}
}

class GetSetDummy
Expand Down Expand Up @@ -872,3 +884,29 @@ public function setFoo($foo)
$this->foo = $foo;
}
}

class GetSetDummyWithOptionalAndMultipleSetterArgs
{
private $foo;
private $bar;

public function getFoo()
{
return $this->foo;
}

public function setFoo($foo = null)
{
$this->foo = $foo;
}

public function getBar()
{
return $this->bar;
}

public function setBar($bar = null, $other = true)
{
$this->bar = $bar;
}
}

0 comments on commit 616c582

Please sign in to comment.