You are here

public function RandomTest::testRandomStringException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/RandomTest.php \Drupal\Tests\Component\Utility\RandomTest::testRandomStringException()

Tests infinite loop prevention whilst generating random strings.

@covers ::string @expectedException \RuntimeException

File

core/tests/Drupal/Tests/Component/Utility/RandomTest.php, line 83
Contains \Drupal\Tests\Component\Utility\RandomTest.

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomStringException() {

  // There are fewer than 100 possibilities so an exception should occur to
  // prevent infinite loops.
  $random = new Random();
  for ($i = 0; $i <= 100; $i++) {
    $str = $random
      ->string(1, TRUE);
    $names[$str] = TRUE;
  }
}