|
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,64 @@ function ($e) {}
|
237 | 238 | $this->assertEquals(['content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result);
|
238 | 239 | }
|
239 | 240 |
|
| 241 | + public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatchesRequestedController() |
| 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 | + |
| 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 | + |
240 | 299 | public function testDispatchWillSeedRouteMatchWithPassedParameters()
|
241 | 300 | {
|
242 | 301 | $result = $this->plugin->dispatch('forward', [
|
|
0 commit comments