Skip to content

Commit

Permalink
fix slice() chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpple committed Nov 7, 2018
1 parent 6731e6e commit afbe6be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Link/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ trait Slice
* @param int $offset
* @param int|null $length
* @param bool $preserveKeys
*
* @return Chain
*/
public function slice($offset, $length = null, $preserveKeys = false)
{
$this->array = array_slice($this->array, $offset, $length, $preserveKeys);

return $this;
}
}
13 changes: 13 additions & 0 deletions tests/Link/SliceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ public function sliceSlicesArray()

$this->assertEquals([1, 2, 3], $mock->array);
}

/**
* @test
* @covers Cocur\Chain\Link\Slice::slice()
*/
public function sliceCanChain()
{
/** @var \Cocur\Chain\Link\Slice $mock */
$mock = $this->getMockForTrait('Cocur\Chain\Link\Slice');
$mock->array = [0, 1, 2, 3, 4, 5];
$result = $mock->slice(1, 3)->array;
$this->assertEquals([1, 2, 3], $result);
}
}

0 comments on commit afbe6be

Please sign in to comment.