[Form] PropertyPath camelizes property names when setting values

This commit is contained in:
Bernhard Schussek 2010-10-10 23:52:02 +02:00 committed by Fabien Potencier
parent a66d883afd
commit b902cb31d7
2 changed files with 21 additions and 1 deletions

View File

@ -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()) {

View File

@ -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');