10000 [Form] PropertyPath camelizes property names when setting values · lcf/symfony@b902cb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b902cb3

Browse files
Bernhard Schussekfabpot
authored andcommitted
[Form] PropertyPath camelizes property names when setting values
1 parent a66d883 commit b902cb3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Symfony/Component/Form/PropertyPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ protected function updateProperty(&$objectOrArray, $currentIndex, $value)
353353
$objectOrArray[$property] = $value;
354354
} else if (is_object($objectOrArray)) {
355355
$reflClass = new \ReflectionClass($objectOrArray);
356-
$setter = 'set'.ucfirst($property); // TODO camelize correctly
356+
$setter = 'set'.$this->camelize($property);
357357

358358
if ($reflClass->hasMethod($setter)) {
359359
if (!$reflClass->getMethod($setter)->isPublic()) {

tests/Symfony/Tests/Component/Form/PropertyPathTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public function testGetValueReadsGetters()
9797
$this->assertEquals('Schussek', $path->getValue($object));
9898
}
9999

100+
public function testGetValueCamelizesGetterNames()
101+
{
102+
$path = new PropertyPath('last_name');
103+
104+
$object = new Author();
105+
$object->setLastName('Schussek');
106+
107+
$this->assertEquals('Schussek', $path->getValue($object));
108+
}
109+
100110
public function testGetValueThrowsExceptionIfGetterIsNotPublic()
101111
{
102112
$path = new PropertyPath('privateGetter');
@@ -205,6 +215,16 @@ public function testSetValueUpdatesSetters()
205215
$this->assertEquals('Schussek', $object->getLastName());
206216
}
207217

218+
public function testSetValueCamelizesSetterNames()
219+
{
220+
$object = new Author();
221+
222+
$path = new PropertyPath('last_name');
223+
$path->setValue($object, 'Schussek');
224+
225+
$this->assertEquals('Schussek', $object->getLastName());
226+
}
227+
208228
public function testSetValueThrowsExceptionIfGetterIsNotPublic()
209229
{
210230
$path = new PropertyPath('privateSetter');

0 commit comments

Comments
 (0)
0