Permalink
Browse files

Make Collection splice return new static.

  • Loading branch information...
KaneCohen committed Nov 17, 2013
1 parent fb9e9e3 commit 32f107dae8c052cc012c272e4d2b2f278b86aade
Showing with 6 additions and 5 deletions.
  1. +1 −1 src/Illuminate/Support/Collection.php
  2. +5 −4 tests/Support/SupportCollectionTest.php
@@ -378,7 +378,7 @@ public function slice($offset, $length = null, $preserveKeys = false)
*/
public function splice($offset, $length = 0, $replacement = array())
{
array_splice($this->items, $offset, $length, $replacement);
return new static(array_splice($this->items, $offset, $length, $replacement));
}
/**
@@ -245,15 +245,16 @@ public function testSplice()
{
$data = new Collection(array('foo', 'baz'));
$data->splice(1, 0, 'bar');
$this->assertEquals(array('foo', 'bar', 'baz'), array_values($data->all()));
$this->assertEquals(array('foo', 'bar', 'baz'), $data->all());
$data = new Collection(array('foo', 'baz'));
$data->splice(1, 1);
$this->assertEquals(array('foo'), array_values($data->all()));
$this->assertEquals(array('foo'), $data->all());
$data = new Collection(array('foo', 'baz'));
$data->splice(1, 1, 'bar');
$this->assertEquals(array('foo', 'bar'), array_values($data->all()));
$cut = $data->splice(1, 1, 'bar');
$this->assertEquals(array('foo', 'bar'), $data->all());
$this->assertEquals(array('baz'), $cut->all());
}
public function testGetListValueWithAccessors()

0 comments on commit 32f107d

Please sign in to comment.