Skip to content

Commit

Permalink
Fixes zendframework#4221 : Set shared false for view_helpers should c…
Browse files Browse the repository at this point in the history
…reate new instance
  • Loading branch information
samsonasik committed Oct 20, 2014
1 parent 3e6936d commit e983b3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Zend/View/Renderer/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function __call($method, $argv)
$this->__pluginCache[$method] = $this->plugin($method);
}
if (is_callable($this->__pluginCache[$method])) {
return call_user_func_array($this->__pluginCache[$method], $argv);
return call_user_func_array($this->plugin($method), $argv);
}
return $this->__pluginCache[$method];
}
Expand Down
21 changes: 21 additions & 0 deletions tests/ZendTest/View/PhpRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,25 @@ public function testIfViewModelComposesVariablesInstanceThenRendererUsesIt()
$test = $this->renderer->render($model);
$this->assertContains('BAR-BAZ-BAT', $test);
}

/**
* @group ZF2-4221
*/
public function testSharedInstanceHelperTest()
{
$helpers = $this->renderer->getHelperPluginManager();
$helpers->setInvokableClass('sharedinstancetest', 'ZendTest\View\TestAsset\SharedInstanceTest');

$helpers->setShared('sharedinstancetest',false);
// new instance always created when shared = false
$this->assertEquals(1, $this->renderer->sharedinstancetest());
$this->assertEquals(1, $this->renderer->sharedinstancetest());
$this->assertEquals(1, $this->renderer->sharedinstancetest());

$helpers->setShared('sharedinstancetest',true);
// use shared instance when shared = true
$this->assertEquals(1, $this->renderer->sharedinstancetest());
$this->assertEquals(2, $this->renderer->sharedinstancetest());
$this->assertEquals(3, $this->renderer->sharedinstancetest());
}
}

0 comments on commit e983b3f

Please sign in to comment.