mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding additional tests for Helper lazy loading.
This commit is contained in:
parent
fc3379767d
commit
68ff2e5ce5
2 changed files with 19 additions and 2 deletions
|
@ -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})) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue