forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zendframework#3650] Do not re-inject EM instance
- If the controller already composes an EM instance, do not re-inject it. This allows factories to inject an EM instance and attach listeners.
- Loading branch information
1 parent
1c3a27e
commit a4353b8
Showing
2 changed files
with
74 additions
and
1 deletion.
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,62 @@ | ||
<?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 | ||
*/ | ||
|
||
namespace ZendTest\Mvc\Controller; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Zend\EventManager\EventManager; | ||
use Zend\EventManager\SharedEventManager; | ||
use Zend\Mvc\Controller\ControllerManager; | ||
use Zend\Mvc\Controller\PluginManager as ControllerPluginManager; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
class ControllerManagerTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->events = new EventManager(); | ||
$this->sharedEvents = new SharedEventManager; | ||
$this->events->setSharedManager($this->sharedEvents); | ||
|
||
$this->plugins = new ControllerPluginManager(); | ||
$this->services = new ServiceManager(); | ||
$this->services->setService('Zend\ServiceManager\ServiceLocatorInterface', $this->services); | ||
$this->services->setService('EventManager', $this->events); | ||
$this->services->setService('SharedEventManager', $this->sharedEvents); | ||
$this->services->setService('ControllerPluginManager', $this->plugins); | ||
|
||
$this->controllers = new ControllerManager(); | ||
$this->controllers->setServiceLocator($this->services); | ||
} | ||
|
||
public function testInjectControllerDependenciesInjectsExpectedDependencies() | ||
{ | ||
$controller = new TestAsset\SampleController(); | ||
$this->controllers->injectControllerDependencies($controller, $this->controllers); | ||
$this->assertSame($this->services, $controller->getServiceLocator()); | ||
$this->assertSame($this->plugins, $controller->getPluginManager()); | ||
|
||
// The default AbstractController implementation lazy instantiates an EM | ||
// instance, which means we need to check that that instance gets injected | ||
// with the shared EM instance. | ||
$events = $controller->getEventManager(); | ||
$this->assertInstanceOf('Zend\EventManager\EventManagerInterface', $events); | ||
$this->assertSame($this->sharedEvents, $events->getSharedManager()); | ||
} | ||
|
||
public function testInjectControllerDependenciesWillNotOverwriteExistingEventManager() | ||
{ | ||
$events = new EventManager(); | ||
$controller = new TestAsset\SampleController(); | ||
$controller->setEventManager($events); | ||
$this->controllers->injectControllerDependencies($controller, $this->controllers); | ||
$this->assertSame($events, $controller->getEventManager()); | ||
$this->assertSame($this->sharedEvents, $events->getSharedManager()); | ||
} | ||
} |