function StorageComparerTest::generateRandomData

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php \Drupal\Tests\Core\Config\StorageComparerTest::generateRandomData()
  2. 10 core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php \Drupal\Tests\Core\Config\StorageComparerTest::generateRandomData()

Generate random data in a config storage.

Parameters

\Drupal\Core\Config\StorageInterface $storage: The storage to populate with random data.

string $prefix: The prefix for random names to make sure they are unique.

1 call to StorageComparerTest::generateRandomData()
StorageComparerTest::testDifferentCollections in core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php
@covers ::createChangelist

File

core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php, line 297

Class

StorageComparerTest
@coversDefaultClass \Drupal\Core\Config\StorageComparer @group Config

Namespace

Drupal\Tests\Core\Config

Code

protected function generateRandomData(StorageInterface $storage, string $prefix = '') : void {
    $generator = $this->getRandomGenerator();
    for ($i = 0; $i < rand(2, 10); $i++) {
        $storage->write($prefix . $this->randomMachineName(), (array) $generator->object());
    }
    for ($i = 0; $i < rand(1, 5); $i++) {
        $collection = $storage->createCollection($prefix . $this->randomMachineName());
        for ($i = 0; $i < rand(2, 10); $i++) {
            $collection->write($prefix . $this->randomMachineName(), (array) $generator->object());
        }
    }
}

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