/** * Inserts an assoc element to container * * @param string $key * @param mixed $value * @param integer $pos * * @return DataContainer * * @throws RuntimeException */ public function insertAssoc($key, $value, $pos = null) { if ($pos === null) { $this->set($key, $value); } else { if ($this->readOnly) { throw new \RuntimeException('Changing values on this Data Container is not allowed.'); } $this->isModified = true; if (abs($pos) > count($this->data)) { $pos = count($this->data) * min(1, max(-1, $pos)); } if ($key === null) { Arr::insert($this->data, $value, $pos); } else { Arr::insertAssoc($this->data, array($key => $value), $pos); } } return $this; }
/** * @covers Fuel\Common\Arr::insert * @expectedException \InvalidArgumentException * @group Common */ public function testInsertException() { $people = array("Jack", "Jill"); Arr::insert($people, "something", 5); }