Ejemplo n.º 1
0
    public function setUp()
    {
        StaticEventManager::resetInstance();

        $mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
        $mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
        $mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
        $mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
        $mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
        $mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));

        $event   = new MvcEvent();
        $event->setApplication($mockApplication);
        $event->setRequest(new Request());
        $event->setResponse(new Response());

        $routeMatch = new RouteMatch(array('action' => 'test'));
        $routeMatch->setMatchedRouteName('some-route');
        $event->setRouteMatch($routeMatch);

        $locator = new Locator;
        $locator->add('forward', function () {
            return new ForwardController();
        });

        $this->controller = new SampleController();
        $this->controller->setEvent($event);
        $this->controller->setServiceLocator($locator);

        $this->plugin = $this->controller->plugin('forward');
    }
Ejemplo n.º 2
0
 public function setUp()
 {
     $event = new MvcEvent();
     $event->setRequest(new Request());
     $event->setResponse(new Response());
     $event->setRouteMatch(new RouteMatch(array('action' => 'test')));
     $locator = new Locator();
     $locator->add('forward', function () {
         return new ForwardController();
     });
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->controller->setServiceLocator($locator);
     $this->plugin = $this->controller->plugin('forward');
 }
Ejemplo n.º 3
0
 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']);
 }