public function testTrigger() { $ev = new Event(); $ev->setData(1, 2); $action = function (Event $ev) { $data = $ev->getData(); return [$data[1], $data[0]]; }; $this->handler->setAction($action); $this->assertEquals([2, 1], $this->handler->trigger($ev)); }
/** * trigger event * @see Event * @param string $key * @param string $function * @param StdClass $data, default = null * @return array, array of responses */ protected function signal($key, $function, StdClass $data = null) { $class = get_called_class(); $response = []; $event = new Event(); $event->setData($data); foreach (array_merge(self::$ghandlers, $this->ihandlers) as $handler) { if ($handler->handles($key, $class, $function)) { $response[] = $handler->trigger($event); } } return $response; }
public function testPassingASingleArgumentToDataSetter() { $this->event->setData([1, 2, 3]); $this->assertEquals([1, 2, 3], $this->event->getData()); }