public static function TestBase::randomObject

Generates a random PHP object.

Parameters

int $size: The number of random keys to add to the object.

Return value

\stdClass The generated object, with the specified number of random keys. Each key has a random string value.

3 calls to TestBase::randomObject()
GarbageCollectionTest::testGarbageCollection in drupal/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php
Tests garbage collection.
StorageTestBase::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
Sets up unit test environment.
TempStoreDatabaseTest::setUp in drupal/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
Sets up unit test environment.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php, line 1154
Definition of Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

public static function randomObject($size = 4) {
  $object = new \stdClass();
  for ($i = 0; $i < $size; $i++) {
    $random_key = self::randomName();
    $random_value = self::randomString();
    $object->{$random_key} = $random_value;
  }
  return $object;
}