|
33 | 33 | use ZendTest\Mvc\Controller\TestAsset\ForwardController;
|
34 | 34 | use ZendTest\Mvc\Controller\TestAsset\SampleController;
|
35 | 35 | use ZendTest\Mvc\Controller\TestAsset\UneventfulController;
|
| 36 | +use ZendTest\Mvc\Controller\Plugin\TestAsset\ListenerStub; |
36 | 37 |
|
37 | 38 | class ForwardTest extends TestCase
|
38 | 39 | {
|
@@ -237,6 +238,35 @@ function ($e) {}
|
237 | 238 | $this->assertEquals(['content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result);
|
238 | 239 | }
|
239 | 240 |
|
| 241 | + public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatchsRequestedController() |
| 242 | + { |
| 243 | + $services = $this->services; |
| 244 | + $events = $services->get('EventManager'); |
| 245 | + |
| 246 | + $myCallback = [new ListenerStub(),'myCallback']; |
| 247 | + $sharedEvents = $this->createMock(SharedEventManagerInterface::class); |
| 248 | + $sharedEvents->expects($this->once())->method('detach')->with($myCallback, 'Zend\Stdlib\DispatchableInterface'); |
| 249 | + $sharedEvents |
| 250 | + ->expects($this->once()) |
| 251 | + ->method('attach') |
| 252 | + ->with('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, $myCallback, -50); |
| 253 | + $sharedEvents->expects($this->any())->method('getListeners')->will($this->returnValue([-50 => [$myCallback]])); |
| 254 | + $events = $this->createEventManager($sharedEvents); |
| 255 | + |
| 256 | + $application = $this->createMock(ApplicationInterface::class); |
| 257 | + $application->expects($this->any())->method('getEventManager')->will($this->returnValue($events)); |
| 258 | + $event = $this->controller->getEvent(); |
| 259 | + $event->setApplication($application); |
| 260 | + |
| 261 | + $this->plugin->setListenersToDetach([[ |
| 262 | + 'id' => 'Zend\Stdlib\DispatchableInterface', |
| 263 | + 'event' => MvcEvent::EVENT_DISPATCH, |
| 264 | + 'class' => 'ZendTest\Mvc\Controller\Plugin\TestAsset\ListenerStub', |
| 265 | + ]]); |
| 266 | + |
| 267 | + $result = $this->plugin->dispatch('forward'); |
| 268 | + } |
| 269 | + |
240 | 270 | public function testDispatchWillSeedRouteMatchWithPassedParameters()
|
241 | 271 | {
|
242 | 272 | $result = $this->plugin->dispatch('forward', [
|
|
0 commit comments