public function RandomTest::testRandomStringUniqueness in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomStringUniqueness()
- 9 core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomStringUniqueness()
Tests unique random string generation.
@covers ::string
File
- core/
tests/ Drupal/ Tests/ Component/ Utility/ RandomTest.php, line 31
Class
- RandomTest
- Tests random data generation.
Namespace
Drupal\Tests\Component\UtilityCode
public function testRandomStringUniqueness() {
$strings = [];
$random = new Random();
for ($i = 0; $i <= 50; $i++) {
$str = $random
->string(1, TRUE);
$this
->assertFalse(isset($strings[$str]), 'Generated duplicate random string ' . $str);
$strings[$str] = TRUE;
}
}