From 68ff2e5ce5eeb23c6ed0e1e723d02c27b345c8d8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jul 2010 11:41:49 -0400 Subject: [PATCH] Adding additional tests for Helper lazy loading. --- cake/libs/view/helper.php | 7 +++++-- cake/tests/cases/libs/view/helper.test.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 2f1b7564a11..77799bf4d11 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -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); @@ -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})) { diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index 039be4965e2..02aaee82f69 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -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); + } }