diff --git a/src/Datasource/EntityTrait.php b/src/Datasource/EntityTrait.php index d59761dbe66..f58ccadff67 100644 --- a/src/Datasource/EntityTrait.php +++ b/src/Datasource/EntityTrait.php @@ -257,7 +257,8 @@ public function &get($property) { } if ($this->_methodExists($method)) { - $value = $this->{$method}($value); + $result = $this->{$method}($value); + return $result; } return $value; } diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 5b45cd415ba..1e7c7513e42 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -180,7 +180,7 @@ public function testGetNoGetters() { */ public function testGetCustomGetters() { $entity = $this->getMock('\Cake\ORM\Entity', ['_getName']); - $entity->expects($this->once())->method('_getName') + $entity->expects($this->exactly(2))->method('_getName') ->with('Jones') ->will($this->returnCallback(function($name) { $this->assertSame('Jones', $name); @@ -188,8 +188,10 @@ public function testGetCustomGetters() { })); $entity->set('name', 'Jones'); $this->assertEquals('Dr. Jones', $entity->get('name')); + $this->assertEquals('Dr. Jones', $entity->get('name')); } + /** * Test magic property setting with no custom setter * @@ -249,20 +251,6 @@ public function testIndirectModification() { $this->assertEquals(['a', 'b', 'c'], $entity->things); } -/** - * Test indirectly modifying internal properties with a getter - * - * @return void - */ - public function testIndirectModificationWithGetter() { - $entity = $this->getMock('\Cake\ORM\Entity', ['_getThings']); - $entity->expects($this->atLeastOnce())->method('_getThings') - ->will($this->returnArgument(0)); - $entity->things = ['a', 'b']; - $entity->things[] = 'c'; - $this->assertEquals(['a', 'b', 'c'], $entity->things); - } - /** * Tests has() method *