Skip to content

Commit

Permalink
Adding additional tests for Helper lazy loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 11, 2010
1 parent fc33797 commit 68ff2e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cake/libs/view/helper.php
Expand Up @@ -171,8 +171,10 @@ public function __construct(View $View, $settings = array()) {
}

/**
* 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);
Expand All @@ -181,7 +183,8 @@ public function __call($method, $params) {
/**
* 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})) {
Expand Down
14 changes: 14 additions & 0 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -805,4 +805,18 @@ function testLazyLoadingHelpers() {
$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);
}
}

0 comments on commit 68ff2e5

Please sign in to comment.