function RandomTest::testRandomMachineNamesUniqueness

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomMachineNamesUniqueness()

Tests unique random name generation.

@covers ::machineName

File

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

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomMachineNamesUniqueness() : void {
    $names = [];
    $random = new Random();
    for ($i = 0; $i <= 10; $i++) {
        $str = $random->machineName(1, TRUE);
        $this->assertArrayNotHasKey($str, $names, '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.