Skip to content
Permalink
Browse files

Fixing an issue where using getters on a Entity field would keep modi…

…fying the field

over and over. This comes at a cost of dropping the indirect modification feature
when using getters in entities.
  • Loading branch information...
lorenzo committed Jul 27, 2014
1 parent 0d66b61 commit 456474c08c477b7acba1f2d946d07681f869f18f
Showing with 5 additions and 16 deletions.
  1. +2 −1 src/Datasource/EntityTrait.php
  2. +3 −15 tests/TestCase/ORM/EntityTest.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;
}
@@ -180,16 +180,18 @@ 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);
return 'Dr. ' . $name;
}));
$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
*

0 comments on commit 456474c

Please sign in to comment.
You can’t perform that action at this time.