Skip to content

Commit

Permalink
Merge ed44d16 into 905f22c
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Jul 4, 2020
2 parents 905f22c + ed44d16 commit 872c13a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ public function toArray(bool $preserveKeys = true): array;
public function toList(): array;

/**
* Convert a result set into JSON.
* Returns the data that can be converted to JSON. This returns the same data
* as `toArray()` which contains only unique keys.
*
* Part of JsonSerializable interface.
*
Expand Down Expand Up @@ -1145,7 +1146,7 @@ public function transpose(): CollectionInterface;
public function count(): int;

/**
* Returns the number of unique keys in this iterator. This is, the number of
* Returns the number of unique keys in this iterator. This is the same as the number of
* elements the collection will contain after calling `toArray()`
*
* This method comes with a number of caveats. Please refer to `CollectionInterface::count()`
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function sumOf($matcher = null)
*/
public function shuffle(): CollectionInterface
{
$elements = $this->toArray();
$elements = $this->toList();
shuffle($elements);

return $this->newCollection($elements);
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,21 @@ public function testShuffle($data)
$this->assertContains(4, $result);
}

/**
* Tests shuffle with duplicate keys.
*
* @return void
*/
public function testShuffleDuplicateKeys()
{
$collection = (new Collection(['a' => 1]))->append(['a' => 2])->shuffle();
$result = $collection->toArray();
$this->assertCount(2, $result);
$this->assertEquals([0, 1], array_keys($result));
$this->assertContainsEquals(1, $result);
$this->assertContainsEquals(2, $result);
}

/**
* Tests sample
*
Expand Down

0 comments on commit 872c13a

Please sign in to comment.