function StorageComparerTest::generateRandomData

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Config/StorageComparerTest.php \Drupal\Tests\Core\Config\StorageComparerTest::generateRandomData()
  2. 11.x 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 293

Class

StorageComparerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21StorageComparer.php/class/StorageComparer/9" title="Defines a config storage comparer." class="local">\Drupal\Core\Config\StorageComparer</a> @group Config

Namespace

Drupal\Tests\Core\Config

Code

protected function generateRandomData(StorageInterface $storage, string $prefix = '') {
    $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.