Skip to content

Commit

Permalink
[5.6] Revert PR that breaks shuffling collection with seed + tests (#…
Browse files Browse the repository at this point in the history
…22813)

* Revert #22807

* Add tests for shuffling collection with seed

* Fix CS
  • Loading branch information
kamui545 authored and taylorotwell committed Jan 16, 2018
1 parent c1e1884 commit cf4a385
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ public function shuffle($seed = null)
srand($seed);

usort($items, function () {
return random_int(-1, 1);
return rand(-1, 1);
});
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ public function testCollectionIsConstructed()
$this->assertEmpty($collection->all());
}

public function testCollectionShuffleWithSeed()
{
$collection = new Collection((range(0, 100, 10)));

$firstRandom = $collection->shuffle(1234);
$secondRandom = $collection->shuffle(1234);

$this->assertEquals($firstRandom, $secondRandom);
}

public function testGetArrayableItems()
{
$collection = new Collection;
Expand Down

0 comments on commit cf4a385

Please sign in to comment.