[Form] PropertyPath camelizes property names when setting values
This commit is contained in:
parent
a66d883afd
commit
b902cb31d7
@ -353,7 +353,7 @@ class PropertyPath implements \IteratorAggregate
|
||||
$objectOrArray[$property] = $value;
|
||||
} else if (is_object($objectOrArray)) {
|
||||
$reflClass = new \ReflectionClass($objectOrArray);
|
||||
$setter = 'set'.ucfirst($property); // TODO camelize correctly
|
||||
$setter = 'set'.$this->camelize($property);
|
||||
|
||||
if ($reflClass->hasMethod($setter)) {
|
||||
if (!$reflClass->getMethod($setter)->isPublic()) {
|
||||
|
@ -97,6 +97,16 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Schussek', $path->getValue($object));
|
||||
}
|
||||
|
||||
public function testGetValueCamelizesGetterNames()
|
||||
{
|
||||
$path = new PropertyPath('last_name');
|
||||
|
||||
$object = new Author();
|
||||
$object->setLastName('Schussek');
|
||||
|
||||
$this->assertEquals('Schussek', $path->getValue($object));
|
||||
}
|
||||
|
||||
public function testGetValueThrowsExceptionIfGetterIsNotPublic()
|
||||
{
|
||||
$path = new PropertyPath('privateGetter');
|
||||
@ -205,6 +215,16 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Schussek', $object->getLastName());
|
||||
}
|
||||
|
||||
public function testSetValueCamelizesSetterNames()
|
||||
{
|
||||
$object = new Author();
|
||||
|
||||
$path = new PropertyPath('last_name');
|
||||
$path->setValue($object, 'Schussek');
|
||||
|
||||
$this->assertEquals('Schussek', $object->getLastName());
|
||||
}
|
||||
|
||||
public function testSetValueThrowsExceptionIfGetterIsNotPublic()
|
||||
{
|
||||
$path = new PropertyPath('privateSetter');
|
||||
|
Reference in New Issue
Block a user