function RandomTest::testRandomStringException
Tests infinite loop prevention whilst generating random strings.
@covers ::string
File
-
core/
tests/ Drupal/ Tests/ Component/ Utility/ RandomTest.php, line 77
Class
- RandomTest
- Tests random data generation.
Namespace
Drupal\Tests\Component\UtilityCode
public function testRandomStringException() {
// There are fewer than 100 possibilities so an exception should occur to
// prevent infinite loops.
$random = new Random();
$this->expectException(\RuntimeException::class);
for ($i = 0; $i <= 100; $i++) {
$str = $random->string(1, TRUE);
$names[$str] = TRUE;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.