public function testDispatchingInjectsLocatorInLocatorAwareControllers() { $app = new Application(); $request = new Request(); $uri = UriFactory::factory('http://example.local/locator-aware'); $request->setUri($uri); $app->setRequest($request); $route = Router\Http\Literal::factory(array('route' => '/locator-aware', 'defaults' => array('controller' => 'locator-aware'))); $router = $app->getRouter(); $router->addRoute('locator-aware', $route); $locator = new TestAsset\Locator(); $locator->add('locator-aware', function () { return new TestAsset\LocatorAwareController(); }); $app->setLocator($locator); $storage = new ArrayObject(); $events = StaticEventManager::getInstance(); $events->attach('ZendTest\\Mvc\\TestAsset\\LocatorAwareController', 'dispatch', function ($e) use($storage) { $controller = $e->getTarget(); $storage['locator'] = $controller->getLocator(); return $e->getResponse(); }, 100); $app->run(); $this->assertTrue(isset($storage['locator'])); $this->assertSame($locator, $storage['locator']); }