function RandomTest::testRandomStringNonUnique

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

Tests random string if uniqueness is not enforced.

@covers ::string

File

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

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomStringNonUnique() : void {
    // There are fewer than 100 possibilities if we were forcing uniqueness so
    // exception would occur.
    $random = new Random();
    for ($i = 0; $i <= 100; $i++) {
        $random->string(1);
    }
    $this->assertTrue(TRUE, 'No exception thrown when uniqueness is not enforced.');
}

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