function RandomTest::testRandomObject

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

Tests random object generation to ensure the expected number of properties.

@covers ::object

File

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

Class

RandomTest
Tests random data generation.

Namespace

Drupal\Tests\Component\Utility

Code

public function testRandomObject() : void {
    // For values of 0 and 1 \Drupal\Component\Utility\Random::object() will
    // have different execution paths.
    $random = new Random();
    for ($i = 0; $i <= 1; $i++) {
        $obj = $random->object($i);
        $this->assertCount($i, get_object_vars($obj), 'Generated random object has expected number of properties');
    }
}

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