/** * @covers Phossa\Event\EventQueue::combine */ public function testCombine() { // callables $call1 = [$this->object, 'count']; $call2 = [$this->object, 'count']; // queue 1 $this->object->insert($call1, 10); // queue 2 $que2 = new EventQueue(); $que2->insert($call2, 20); $que3 = $this->object->combine($que2); // type right $this->assertTrue($que3 instanceof EventQueueInterface); // count right $this->assertTrue(2 === $que3->count()); }
/** * Attach callable to event queque * * @param string $eventName event name * @param EventListenerInterface|string|null $listener * object/static class name or a callable * @param mixed $callable string | array * @param int $priority priority integer * @return void * @throws Exception\InvalidArgumentException * if callable is the wrong format * @access protected */ protected function attachIt($eventName, $listener, $callable, $priority) { // get named event queue if ($this->hasEventQueue($eventName)) { $q = $this->getEventQueue($eventName); } else { $q = new EventQueue(); $this->events[$eventName] = $q; } // attach callable directory if (is_null($listener)) { // need $eventName if (empty($eventName)) { throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_NAME, 'EMPTY'), Message::INVALID_EVENT_NAME); } $xc = [[$callable, (int) $priority]]; // get callables from listener object or static listener class } else { $xc = $this->makeCallables($listener, $callable, (int) $priority); } if (empty($xc)) { throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_EVENT_CALLABLE, $eventName), Message::INVALID_EVENT_CALLABLE); } else { foreach ($xc as $c) { $q->insert($c[0], $c[1]); } } }