Skip to content
Permalink
Browse files

Add constructor injection for the eventManager.

This should help enable the ActionDispatcher inside the present day
Dispatcher.
  • Loading branch information...
markstory committed Apr 17, 2016
1 parent 71623f5 commit 5a90c3dec2056e45e0dd8763f0575ac0b97455fb
Showing with 21 additions and 1 deletion.
  1. +6 −1 src/Http/ActionDispatcher.php
  2. +15 −0 tests/TestCase/Http/ActionDispatcherTest.php
@@ -54,9 +54,14 @@ class ActionDispatcher
* Constructor
*
* @param \Cake\Http\ControllerFactory $factory A controller factory instance.
* @param \Cake\Event\EventManager $eventManager An event manager if you want to inject one.
*/
public function __construct($factory = null)
public function __construct($factory = null, $eventManager = null)
{
if ($eventManager) {
$this->eventManager($eventManager);
}
// Compatibility with DispatcherFilters.
foreach (DispatcherFactory::filters() as $filter) {
$this->addFilter($filter);
@@ -54,6 +54,21 @@ public function tearDown()
DispatcherFactory::clear();
}
/**
* Ensure the constructor args end up on the right protected properties.
*
* @return void
*/
public function testConstructorArgs()
{
$factory = $this->getMock('Cake\Http\ControllerFactory');
$events = $this->getMock('Cake\Event\EventManager');
$dispatcher = new ActionDispatcher($factory, $events);
$this->assertAttributeSame($events, '_eventManager', $dispatcher);
$this->assertAttributeSame($factory, 'factory', $dispatcher);
}
/**
* Ensure that filters connected to the DispatcherFactory are
* also applied

0 comments on commit 5a90c3d

Please sign in to comment.
You can’t perform that action at this time.