From cf4a385c30c193da6ffda3e2ef40efd98251fcb1 Mon Sep 17 00:00:00 2001 From: Emmanuel Maggion Date: Tue, 16 Jan 2018 20:37:20 +0700 Subject: [PATCH] [5.6] Revert PR that breaks shuffling collection with seed + tests (#22813) * Revert #22807 * Add tests for shuffling collection with seed * Fix CS --- src/Illuminate/Support/Collection.php | 2 +- tests/Support/SupportCollectionTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 7bad468ffde8..757f3593c55d 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1309,7 +1309,7 @@ public function shuffle($seed = null) srand($seed); usort($items, function () { - return random_int(-1, 1); + return rand(-1, 1); }); } diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 68704911325e..1327a34aea42 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -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;