FOF30\Model\DataModel\Collection::merge PHP 메소드

merge() 공개 메소드

Merge the collection with the given items.
public merge ( Collection | array $collection ) : Collection
$collection FOF30\Utils\Collection | array
리턴 FOF30\Utils\Collection
    public function merge($collection)
    {
        $dictionary = $this->getDictionary($this);
        foreach ($collection as $item) {
            $dictionary[$item->getId()] = $item;
        }
        return new static(array_values($dictionary));
    }

Usage Example

예제 #1
0
 /**
  * @group           DataModel
  * @group           CollectionMerge
  * @covers          FOF30\Model\DataModel\Collection::merge
  */
 public function testMerge()
 {
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     $model = $this->getMock('\\FOF30\\Tests\\Stubs\\Model\\DataModelStub', array('getState'), array(static::$container, $config));
     $collection1 = new Collection($model->getItemsArray(0, 2));
     $collection2 = new Collection($model->getItemsArray(2, 1));
     $merge = $collection1->merge($collection2);
     $this->assertInstanceOf('\\FOF30\\Model\\DataModel\\Collection', $merge, 'Collection::merge Should return an instance of Collection');
     $this->assertCount(3, $merge, 'Collection::merge Failed to merge two arrays');
 }