Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
v5.2.43 changes (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Aug 10, 2016
1 parent ce69909 commit 6add72f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Countable;
use ArrayAccess;
use Traversable;
use ArrayIterator;
use CachingIterator;
use JsonSerializable;
Expand Down Expand Up @@ -1241,6 +1242,8 @@ protected function getArrayableItems($items)
return json_decode($items->toJson(), true);
} elseif ($items instanceof JsonSerializable) {
return $items->jsonSerialize();
} elseif ($items instanceof Traversable) {
return iterator_to_array($items);
}

return (array) $items;
Expand Down
48 changes: 48 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,54 @@ public function testWithMultipleModeValues()
$collection = new Collection([1, 2, 2, 1]);
$this->assertEquals([1, 2], $collection->mode());
}

public function testSliceOffset()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([4, 5, 6, 7, 8], $collection->slice(3)->values()->toArray());
}

public function testSliceNegativeOffset()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([6, 7, 8], $collection->slice(-3)->values()->toArray());
}

public function testSliceOffsetAndLength()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([4, 5, 6], $collection->slice(3, 3)->values()->toArray());
}

public function testSliceOffsetAndNegativeLength()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([4, 5, 6, 7], $collection->slice(3, -1)->values()->toArray());
}

public function testSliceNegativeOffsetAndLength()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([4, 5, 6], $collection->slice(-5, 3)->values()->toArray());
}

public function testSliceNegativeOffsetAndNegativeLength()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray());
}

public function testCollectonFromTraversable()
{
$collection = new Collection(new \ArrayObject([1, 2, 3]));
$this->assertEquals([1, 2, 3], $collection->toArray());
}

public function testCollectonFromTraversableWithKeys()
{
$collection = new Collection(new \ArrayObject(['foo' => 1, 'bar' => 2, 'baz' => 3]));
$this->assertEquals(['foo' => 1, 'bar' => 2, 'baz' => 3], $collection->toArray());
}
}

class TestAccessorEloquentTestStub
Expand Down

0 comments on commit 6add72f

Please sign in to comment.