function StorageCopyTraitTest::generateRandomData

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::generateRandomData()
  2. 8.9.x core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::generateRandomData()
  3. 10 core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::generateRandomData()

Generate random data in a config storage.

Parameters

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

bool $collections: Add random collections or not.

2 calls to StorageCopyTraitTest::generateRandomData()
StorageCopyTraitTest::testReplaceStorageContents in core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php
@covers ::replaceStorageContents
StorageCopyTraitTest::testWithInvalidConfiguration in core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php
Tests replaceStorageContents() with config with an invalid configuration.

File

core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php, line 104

Class

StorageCopyTraitTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21StorageCopyTrait.php/trait/StorageCopyTrait/11.x" title="Utility trait to copy configuration from one storage to another." class="local">\Drupal\Core\Config\StorageCopyTrait</a> @group Config

Namespace

Drupal\Tests\Core\Config

Code

protected function generateRandomData(StorageInterface $storage, $collections = TRUE) {
    $generator = $this->getRandomGenerator();
    for ($i = 0; $i < rand(2, 10); $i++) {
        $storage->write($this->randomMachineName(), (array) $generator->object());
    }
    if ($collections) {
        for ($i = 0; $i < rand(1, 5); $i++) {
            $collection = $storage->createCollection($this->randomMachineName());
            for ($i = 0; $i < rand(2, 10); $i++) {
                $collection->write($this->randomMachineName(), (array) $generator->object());
            }
        }
    }
}

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