Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 17d7398

Browse files
committed
Add additional test for ForwardPlugin, fix typo
1 parent 860e140 commit 17d7398

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

test/Controller/Plugin/ForwardTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function ($e) {}
238238
$this->assertEquals(['content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result);
239239
}
240240

241-
public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatchsRequestedController()
241+
public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatchesRequestedController()
242242
{
243243
$services = $this->services;
244244
$events = $services->get('EventManager');
@@ -267,6 +267,35 @@ public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatchsR
267267
$result = $this->plugin->dispatch('forward');
268268
}
269269

270+
public function testInvokableProblemListenersAreDetachedAndReattachedWhenPluginDispatchesRequestedController()
271+
{
272+
$services = $this->services;
273+
$events = $services->get('EventManager');
274+
275+
$myCallback = new ListenerStub();
276+
$sharedEvents = $this->createMock(SharedEventManagerInterface::class);
277+
$sharedEvents->expects($this->once())->method('detach')->with($myCallback, 'Zend\Stdlib\DispatchableInterface');
278+
$sharedEvents
279+
->expects($this->once())
280+
->method('attach')
281+
->with('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, $myCallback, -50);
282+
$sharedEvents->expects($this->any())->method('getListeners')->will($this->returnValue([-50 => [$myCallback]]));
283+
$events = $this->createEventManager($sharedEvents);
284+
285+
$application = $this->createMock(ApplicationInterface::class);
286+
$application->expects($this->any())->method('getEventManager')->will($this->returnValue($events));
287+
$event = $this->controller->getEvent();
288+
$event->setApplication($application);
289+
290+
$this->plugin->setListenersToDetach([[
291+
'id' => 'Zend\Stdlib\DispatchableInterface',
292+
'event' => MvcEvent::EVENT_DISPATCH,
293+
'class' => 'ZendTest\Mvc\Controller\Plugin\TestAsset\ListenerStub',
294+
]]);
295+
296+
$result = $this->plugin->dispatch('forward');
297+
}
298+
270299
public function testDispatchWillSeedRouteMatchWithPassedParameters()
271300
{
272301
$result = $this->plugin->dispatch('forward', [

test/Controller/Plugin/TestAsset/ListenerStub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
class ListenerStub
55
{
6+
public function __invoke()
7+
{
8+
}
9+
610
public function myCallback()
711
{
812
}

0 commit comments

Comments
 (0)