public function connect($receiver, $sender = null, $behavior = Centurion_Signal::BEHAVIOR_CONTINUE, $method = Centurion_Signal_Abstract::PUSH) { if (!is_array($sender)) { $receiver = array(Centurion_Signal::RECEIVER => $receiver, Centurion_Signal::BEHAVIOR => $behavior); } if (is_object($sender)) { if ($method === Centurion_Signal_Abstract::UNSHIFT) { $this->_setupObjectContainer($sender)->unshift($receiver); } else { $this->_setupObjectContainer($sender)->push($receiver); } return $this; } elseif (is_string($sender)) { if ($method === Centurion_Signal_Abstract::UNSHIFT) { $this->_classnameCollection->unshift(array($sender => $receiver)); } else { $this->_classnameCollection->push(array($sender => $receiver)); } return $this; } elseif (is_array($sender)) { foreach ($sender as $val) { $this->connect($receiver, $val, $method); } return $this; } return $this->push($receiver); }
public function testAll() { $collection = new Centurion_Collection(); $this->assertEquals(0, $collection->count()); $this->assertEquals(0, count($collection)); $original = array(1, 2); $collection->setData($original); $this->assertEquals($original, $collection->getData()); $this->assertEquals($original, $collection->toArray()); $this->assertEquals(1, $collection->getFirst()); $this->assertEquals(2, $collection->getLast()); $this->assertEquals(2, $collection->pop()); $this->assertEquals(1, $collection->pop()); $this->assertEquals(0, $collection->count()); $this->assertEquals(0, count($collection)); foreach ($original as $key => $val) { $collection[$key] = $val; $this->assertEquals($val, $collection[$key]); } $collection->remove(0); try { $collection[0]; $this->fail('Centurion_Collection should throw an exception when we try to access something that doesn\'t exist.'); } catch (Centurion_Exception $e) { //It's normal to be here } }