function RandomTest::testRandomNamesUniqueness

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomNamesUniqueness()
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomNamesUniqueness()
  3. 11.x core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomNamesUniqueness()

Tests unique random name generation.

@covers ::name

File

core/tests/Drupal/Tests/Component/Utility/RandomTest.php, line 48

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomNamesUniqueness() : void {
  $names = [];
  $random = new Random();
  for ($i = 0; $i <= 10; $i++) {
    $str = $random->name(1, TRUE);
    $this->assertFalse(isset($names[$str]), 'Generated duplicate random name ' . $str);
    $names[$str] = TRUE;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.