Skip to content
Permalink
Browse files

Using a more agressive cache invalidaiton technique in entity

mutators cache. Fixes #6522
  • Loading branch information...
lorenzo committed May 10, 2015
1 parent 6c4e7ab commit 83aa707de9da9263023b51194e4092a0349c9d6f
Showing with 24 additions and 2 deletions.
  1. +3 −2 src/Datasource/EntityTrait.php
  2. +21 −0 tests/TestCase/ORM/EntityTest.php
@@ -242,7 +242,6 @@ public function set($property, $value = null, array $options = [])
continue;
}
unset($this->_mutated[$p]);
$this->dirty($p, true);
if (!isset($this->_original[$p]) &&
@@ -263,6 +262,8 @@ public function set($property, $value = null, array $options = [])
}
$this->_properties[$p] = $value;
}
$this->_mutated = [];
return $this;
}
@@ -364,9 +365,9 @@ public function unsetProperty($property)
foreach ($property as $p) {
unset($this->_properties[$p]);
unset($this->_dirty[$p]);
unset($this->_mutated[$p]);
}
$this->_mutated = [];
return $this;
}
@@ -277,6 +277,27 @@ public function testGetCacheClearedByUnset()
$this->assertEquals('Dr. ', $entity->get('name'));
}
/**
* Tests that the get cache is cleared by setting any property.
* This is because virtual properties can often rely on other
* properties in the entity.
*
* @return void
*/
public function testGetCacheClearedBySet()
{
$entity = $this->getMock('\Cake\ORM\Entity', ['_getName']);
$entity->last_name = 'Smith';
$entity->name = 'John';
$entity->expects($this->any())->method('_getName')
->will($this->returnCallback(function ($name) use ($entity) {
return 'Dr. ' . $name . ' ' . $entity->last_name;
}));
$this->assertEquals('Dr. John Smith', $entity->get('name'));
$entity->last_name = 'Jones';
$this->assertEquals('Dr. John Jones', $entity->get('name'));
}
/**
* Test magic property setting with no custom setter

0 comments on commit 83aa707

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