This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3085] Ensure controller is current in plugin manager
- When fetching the plugin manager, inject the current controller *always*; this ensures that if a plugin is retrieved, it receives the controller that actually requested it.
- Loading branch information
1 parent
44b7108
commit bb2e97b
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mvc | ||
*/ | ||
|
||
namespace ZendTest\Mvc\Controller; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Zend\EventManager\SharedEventManager; | ||
use Zend\Mvc\Controller\ControllerManager; | ||
use Zend\Mvc\Controller\PluginManager; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
class IntegrationTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->plugins = new PluginManager(); | ||
$this->sharedEvents = new SharedEventManager(); | ||
$this->services = new ServiceManager(); | ||
$this->services->setService('ControllerPluginManager', $this->plugins); | ||
$this->services->setService('SharedEventManager', $this->sharedEvents); | ||
$this->services->setService('Zend\ServiceManager\ServiceLocatorInterface', $this->services); | ||
|
||
$this->controllers = new ControllerManager(); | ||
$this->controllers->setServiceLocator($this->services); | ||
} | ||
|
||
public function testPluginReceivesCurrentController() | ||
{ | ||
$this->controllers->setInvokableClass('first', 'ZendTest\Mvc\Controller\TestAsset\SampleController'); | ||
$this->controllers->setInvokableClass('second', 'ZendTest\Mvc\Controller\TestAsset\SampleController'); | ||
|
||
$first = $this->controllers->get('first'); | ||
$second = $this->controllers->get('second'); | ||
$this->assertNotSame($first, $second); | ||
|
||
$plugin1 = $first->plugin('url'); | ||
$this->assertSame($first, $plugin1->getController()); | ||
|
||
$plugin2 = $second->plugin('url'); | ||
$this->assertSame($second, $plugin2->getController()); | ||
|
||
$this->assertSame($plugin1, $plugin2); | ||
} | ||
} |