|
28 | 28 | use function mt_rand;
|
29 | 29 | use function range;
|
30 | 30 | use function spl_object_hash;
|
| 31 | +use function sprintf; |
31 | 32 | use function strlen;
|
32 | 33 | use function strnatcmp;
|
33 | 34 |
|
@@ -1476,16 +1477,31 @@ public function testWillRemoveItemAtSpecificPosition(): void
|
1476 | 1477 |
|
1477 | 1478 | public function testWillShuffleValuesInList(): void
|
1478 | 1479 | {
|
1479 |
| - $list = new GenericOrderedList([ |
1480 |
| - 1, |
1481 |
| - 2, |
1482 |
| - 3, |
1483 |
| - ]); |
| 1480 | + $values = [1, 2, 3]; |
| 1481 | + $list = new GenericOrderedList($values); |
| 1482 | + |
| 1483 | + $maximumShuffleAttempts = 10; |
| 1484 | + $shuffledSameCount = 0; |
| 1485 | + |
| 1486 | + do { |
| 1487 | + $list2 = $list->shuffle(); |
| 1488 | + /** @psalm-suppress TypeDoesNotContainType No clue why this is happening but for now we are suppressing */ |
| 1489 | + if ($list2->toNativeArray() === $values) { |
| 1490 | + $shuffledSameCount++; |
| 1491 | + self::assertLessThan( |
| 1492 | + $maximumShuffleAttempts, |
| 1493 | + $shuffledSameCount, |
| 1494 | + sprintf('The shuffle did not change the order after "%d" attempts.', $maximumShuffleAttempts), |
| 1495 | + ); |
| 1496 | + continue; |
| 1497 | + } |
| 1498 | + |
| 1499 | + break; |
| 1500 | + } while ($shuffledSameCount < $maximumShuffleAttempts); |
1484 | 1501 |
|
1485 |
| - $list2 = $list->shuffle(); |
1486 |
| - self::assertSame([1, 2, 3], $list->toNativeArray()); |
1487 | 1502 | self::assertNotSame($list, $list2);
|
1488 |
| - self::assertNotSame([1, 2, 3], $list2->toNativeArray()); |
| 1503 | + self::assertEqualsCanonicalizing($values, $list2->toNativeArray()); |
| 1504 | + self::assertNotSame($values, $list2->toNativeArray()); |
1489 | 1505 | }
|
1490 | 1506 |
|
1491 | 1507 | public function testWillCombineWithAnohterList(): void
|
|
0 commit comments