public function itFallbackToCallHookIfGivenCallbackDoesNotExist() { $event = 'an_event'; $params = array('some_params'); $listener = new Event2MockEventListener($this); stub($listener)->CallHook($event, $params)->once(); $em = new EventManager(); $em->addListener($event, $listener, 'doSomething', false); $em->processEvent($event, $params); }
function testProcessEvent1() { //The listeners $l1 = new Event1MockEventListener($this); $l1->expectOnce('doSomething'); $l2 = new Event1MockEventListener($this); $l2->expectOnce('doSomething'); $l3 = new Event2MockEventListener($this); $l3->expectNever('CallHook'); //The events $e1 = 'event1'; $e2 = 'event2'; //The event Manager $m = new EventManager(); //We register the listeners for the type $m->addListener($e1, $l1, 'doSomething', false, 0); $m->addListener($e1, $l2, 'doSomething', false, 0); $m->addListener($e2, $l3, 'CallHook', true, 0); //We process event $params = array(); $m->processEvent($e1, $params); }
public function itRaisesAnExceptionIfPluginForbidLogin() { $this->expectException('User_InvalidPasswordWithUserException'); $user = aUser()->withPassword('password')->withStatus(PFUser::STATUS_ACTIVE)->build(); stub($this->user_manager)->getUserByUserName()->returns($user); $this->event_manager->addListener(Event::SESSION_AFTER_LOGIN, $this, 'refuseLogin', false); $this->login_manager->authenticate('john', 'password'); }
public function setUp() { parent::setUp(); $event_manager = new EventManager(); $event_manager->addListener(Event::GET_LDAP_LOGIN_NAME_FOR_USER, $this, 'hookReturnsLdapUser', false, 0); EventManager::setInstance($event_manager); $this->ldap_login = '******'; $this->ldap_result = stub('LDAPResult')->getLogin()->returns($this->ldap_login); }
private function addListener($hook, PluginProxy $proxy) { $proxy->addListener($hook['event'], $hook['callback'], $hook['recall_event']); $this->event_manager->addListener($hook['event'], $proxy, 'processEvent', true); }
public function itPassUserByReference() { $user_row = array('user_id' => 90); $event_manager = new EventManager(); $event_manager->addListener(Event::USER_MANAGER_GET_USER_INSTANCE, $this, 'mockedMethodForEventTest', false, 0); EventManager::setInstance($event_manager); $result_expected = 'thatValue'; $result = $this->user_manager->getUserInstanceFromRow($user_row); $this->assertEqual($result, $result_expected); }
/** * Attach handler with EventManager. * * @return void */ public function attach() { foreach ($this->eventNames as $callable) { $this->dispatcher->addListener($callable['name'], array($this, $callable['method']), $callable['weight']); } }
/** * add an event listener to the event driven application * @access public * @param string methodName callback method, must be a method of the * current event-driven instance * @param string eventType event type * @return string eventlistener ID */ public function addListener($eventType, $methodName) { $listener = new EventListener(array(&$this, $methodName)); return EventManager::addListener($eventType, $listener); }