diff --git a/src/Link/Slice.php b/src/Link/Slice.php index 853500f..20876e8 100644 --- a/src/Link/Slice.php +++ b/src/Link/Slice.php @@ -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; } } diff --git a/tests/Link/SliceTest.php b/tests/Link/SliceTest.php index 3cf7e50..e788ec4 100644 --- a/tests/Link/SliceTest.php +++ b/tests/Link/SliceTest.php @@ -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); + } }