function StorageCopyTraitTest::generateRandomData

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

Class

StorageCopyTraitTest
@coversDefaultClass \Drupal\Core\Config\StorageCopyTrait @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.