Collections\Collection::merge PHP Method

merge() public method

public merge ( $items )
    public function merge($items)
    {
        if ($items instanceof static) {
            $items = $items->toArray();
        }
        if (!is_array($items)) {
            throw new InvalidArgumentException("Merge must be given array or Collection");
        }
        $this->validateItems($items, $this->type);
        $newItems = array_merge($this->items, $items);
        $col = new static($this->type);
        $col->setItemsFromTrustedSource($newItems);
        return $col;
    }

Usage Example

 public function test_non_array_or_col_throws_ex()
 {
     $this->expectException(InvalidArgumentException::class);
     $col = new Collection('TestClassA');
     $col->merge(new TestClassA(1));
 }