|
19 | 19 | use Zend\Mvc\MvcEvent;
|
20 | 20 | use Zend\Router\RouteMatch;
|
21 | 21 | use Zend\ServiceManager\ServiceManager;
|
| 22 | +use Zend\Stdlib\ResponseInterface; |
| 23 | +use Zend\View\Model\ModelInterface; |
22 | 24 |
|
23 | 25 | class DispatchListenerTest extends TestCase
|
24 | 26 | {
|
@@ -83,4 +85,49 @@ public function testUnlocatableControllerViaAbstractFactory()
|
83 | 85 | $this->assertArrayHasKey('error', $log);
|
84 | 86 | $this->assertSame('error-controller-not-found', $log['error']);
|
85 | 87 | }
|
| 88 | + |
| 89 | + /** |
| 90 | + * @dataProvider alreadySetMvcEventResultProvider |
| 91 | + * |
| 92 | + * @param mixed $alreadySetResult |
| 93 | + */ |
| 94 | + public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetResult) |
| 95 | + { |
| 96 | + $event = $this->createMvcEvent('path'); |
| 97 | + |
| 98 | + $event->setResult($alreadySetResult); |
| 99 | + |
| 100 | + $listener = new DispatchListener(new ControllerManager(new ServiceManager(), ['abstract_factories' => [ |
| 101 | + Controller\TestAsset\UnlocatableControllerLoaderAbstractFactory::class, |
| 102 | + ]])); |
| 103 | + |
| 104 | + $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function () { |
| 105 | + self::fail('No dispatch failures should be raised - dispatch should be skipped'); |
| 106 | + }); |
| 107 | + |
| 108 | + $listener->onDispatch($event); |
| 109 | + |
| 110 | + self::assertSame($alreadySetResult, $event->getResult(), 'The event result was not replaced'); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * @return mixed[][] |
| 115 | + */ |
| 116 | + public function alreadySetMvcEventResultProvider() |
| 117 | + { |
| 118 | + return [ |
| 119 | + [123], |
| 120 | + [true], |
| 121 | + [false], |
| 122 | + [[]], |
| 123 | + [new \stdClass()], |
| 124 | + [$this], |
| 125 | + [$this->createMock(ModelInterface::class)], |
| 126 | + [$this->createMock(ResponseInterface::class)], |
| 127 | + [$this->createMock(Response::class)], |
| 128 | + [['view model data' => 'as an array']], |
| 129 | + [['foo' => new \stdClass()]], |
| 130 | + ['a response string'], |
| 131 | + ]; |
| 132 | + } |
86 | 133 | }
|
0 commit comments