Skip to content

Commit

Permalink
Allow camelBacked virtualProperties to be accessed.
Browse files Browse the repository at this point in the history
This fixes a regression introduced in while optimizing entity accessors.

Refs #8246
  • Loading branch information
markstory committed Feb 12, 2016
1 parent a524970 commit 460fbf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Datasource/EntityTrait.php
Expand Up @@ -535,7 +535,9 @@ protected static function _accessor($property, $type)
if ($method[0] !== '_' || ($prefix !== 'get' && $prefix !== 'set')) {
continue;
}
$field = Inflector::underscore(substr($method, 4));
$field = lcfirst(substr($method, 4));
$snakeField = Inflector::underscore($field);
static::$_accessors[$class][$prefix][$snakeField] = $method;
static::$_accessors[$class][$prefix][$field] = $method;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -312,6 +312,23 @@ public function testGetCacheClearedByUnset()
$this->assertEquals('Dr. ', $entity->get('name'));
}

/**
* Test getting camelcased virtual fields.
*
* @return void
*/
public function testGetCamelCasedProperties()
{
$entity = $this->getMock('\Cake\ORM\Entity', ['_getListIdName']);
$entity->expects($this->any())->method('_getListIdName')
->will($this->returnCallback(function ($name) {
return 'A name';
}));
$entity->virtualProperties(['ListIdName']);
$this->assertSame('A name', $entity->list_id_name, 'underscored virtual field should be accessible');
$this->assertSame('A name', $entity->listIdName, 'Camelbacked virtual field should be accessible');
}

/**
* Test magic property setting with no custom setter
*
Expand Down

0 comments on commit 460fbf2

Please sign in to comment.