Adding additional tests for Helper lazy loading.

This commit is contained in:
mark_story 2010-07-03 11:41:49 -04:00
parent fc3379767d
commit 68ff2e5ce5
2 changed files with 19 additions and 2 deletions

View file

@ -171,8 +171,10 @@ class Helper extends Object {
}
/**
* Default overload methods
* Provide non fatal errors on missing method calls.
*
* @param string $method Method to invoke
* @param array $params Array of params for the method.
*/
public function __call($method, $params) {
trigger_error(sprintf(__('Method %1$s::%2$s does not exist'), get_class($this), $method), E_USER_WARNING);
@ -181,7 +183,8 @@ class Helper extends Object {
/**
* Lazy loads helpers
*
* @return void
* @param string $name Name of the property being accessed.
* @return mixed Helper or property found at $name
*/
public function __get($name) {
if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {

View file

@ -805,4 +805,18 @@ class HelperTest extends CakeTestCase {
$this->assertType('HtmlHelper', $Helper->Html);
App::build();
}
/**
* test that the lazy loader doesn't duplicate objects on each access.
*
* @return void
*/
function testLazyLoadingUsesReferences() {
$Helper = new TestHelper($this->View);
$result1 = $Helper->Html;
$result2 = $Helper->Html;
$result1->testprop = 1;
$this->assertEquals($result1->testprop, $result2->testprop);
}
}