Skip to content

Commit

Permalink
specify method. rename conjoin
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 25, 2017
1 parent 8d0a9b7 commit 0f5337f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
34 changes: 17 additions & 17 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,6 @@ public function collapse()
return new static(Arr::collapse($this->items));
}

/**
* Conjoin all values of a collection with those of another, regardless of keys.
*
* @param \Traversable $source
* @return self
*/
public function conjoin($source)
{
$joinedCollection = new static($this);

foreach ($source as $item) {
$joinedCollection->push($item);
}

return $joinedCollection;
}

/**
* Determine if an item exists in the collection.
*
Expand Down Expand Up @@ -1008,6 +991,23 @@ public function push($value)
return $this;
}

/**
* Push all of the given items onto the collection.
*
* @param \Traversable $source
* @return self
*/
public function concat($source)
{
$result = new static($this);

foreach ($source as $item) {
$result->push($item);
}

return $result;
}

/**
* Get and remove an item from the collection.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/DatabaseEloquentHasOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testHasOneWithArrayDefault()
public function testMakeMethodDoesNotSaveNewModel()
{
$relation = $this->getRelation();
$instance = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['newInstance', 'setAttribute'])->getMock();
$instance = $this->getMockBuilder('Illuminate\Database\Eloquent\Model')->setMethods(['save', 'newInstance', 'setAttribute'])->getMock();
$relation->getRelated()->shouldReceive('newInstance')->with(['name' => 'taylor'])->andReturn($instance);
$instance->expects($this->once())->method('setAttribute')->with('foreign_key', 1);
$instance->expects($this->never())->method('save');
Expand Down
16 changes: 8 additions & 8 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ public function testCombineWithCollection()
$this->assertSame($expected, $actual);
}

public function testConJoinWithArray()
public function testConcatWithArray()
{
$expected = [
0 => 4,
Expand All @@ -1740,14 +1740,14 @@ public function testConJoinWithArray()
];

$collection = new Collection([4, 5, 6]);
$collection = $collection->conjoin(['a', 'b', 'c']);
$collection = $collection->conjoin(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe']);
$actual = $collection->conjoin(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'])->toArray();
$collection = $collection->concat(['a', 'b', 'c']);
$collection = $collection->concat(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe']);
$actual = $collection->concat(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe'])->toArray();

$this->assertSame($expected, $actual);
}

public function testConJoinWithCollection()
public function testConcatWithCollection()
{
$expected = [
0 => 4,
Expand All @@ -1767,9 +1767,9 @@ public function testConJoinWithCollection()
$firstCollection = new Collection([4, 5, 6]);
$secondCollection = new Collection(['a', 'b', 'c']);
$thirdCollection = new Collection(['who' => 'Jonny', 'preposition' => 'from', 'where' => 'Laroe']);
$firstCollection = $firstCollection->conjoin($secondCollection);
$firstCollection = $firstCollection->conjoin($thirdCollection);
$actual = $firstCollection->conjoin($thirdCollection)->toArray();
$firstCollection = $firstCollection->concat($secondCollection);
$firstCollection = $firstCollection->concat($thirdCollection);
$actual = $firstCollection->concat($thirdCollection)->toArray();

$this->assertSame($expected, $actual);
}
Expand Down

0 comments on commit 0f5337f

Please sign in to comment.