MemoryStorage example

parent::setUp();
    $this->installConfig(['system']);
  }

  /** * Tests the import transformation. */
  public function testTransform() {
    // Get the raw system.site config and set it in the sync storage.     $rawConfig = $this->config('system.site')->getRawData();

    $storage = new MemoryStorage();
    $this->copyConfig($this->container->get('config.storage')$storage);

    $import = $this->container->get('config.import_transformer')->transform($storage);
    $config = $import->read('system.site');
    // The test subscriber always adds "Arrr" to the current site name.     $this->assertEquals($rawConfig['name'] . ' Arrr', $config['name']);
    $this->assertEquals($rawConfig['slogan']$config['slogan']);

    // Update the site config in the storage to test a second transformation.     $config['name'] = 'New name';
    $config['slogan'] = 'New slogan';
    

  protected $collections = [];

  /** * {@inheritdoc} */
  public function get($collection) {
    if (!isset($this->collections[$collection])) {
      $this->collections[$collection] = new MemoryStorage($collection);
    }
    return $this->collections[$collection];
  }

}

  protected $storage;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Set up a memory storage we can manipulate to set fixtures.     $this->memory = new MemoryStorage();
    // Wrap the memory storage in the read-only storage to test it.     $this->storage = new ReadOnlyStorage($this->memory);
  }

  /** * @covers ::exists * @covers ::read * @covers ::readMultiple * @covers ::listAll * * @dataProvider readMethodsProvider */
/** * @coversDefaultClass \Drupal\Core\Config\ExtensionInstallStorage * @group Config */
class ExtensionInstallStorageTest extends UnitTestCase {

  /** * @covers ::createCollection */
  public function testCreateCollection() {
    $memory = new MemoryStorage();
    $include_profile = FALSE;
    $profile = $this->randomMachineName();
    $collectionName = $this->randomMachineName();

    // Set up the storage.     $storage = new ExtensionInstallStorage($memory, InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, $include_profile$profile);
    // Create a collection.     $collection = $storage->createCollection($collectionName);

    static::assertEquals($collectionName$collection->getCollectionName());
  }

}

class StorageCopyTraitTest extends UnitTestCase {

  use StorageCopyTrait;

  /** * @covers ::replaceStorageContents * * @dataProvider providerTestReplaceStorageContents */
  public function testReplaceStorageContents($source_collections$target_collections) {
    $source = new MemoryStorage();
    $target = new MemoryStorage();
    // Empty the storage should be the same.     $this->assertEquals(self::toArray($source), self::toArray($target));

    // When the source is populated, they are not the same any more.     $this->generateRandomData($source$source_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    // When the target is filled with random data they are also not the same.     $this->generateRandomData($target$target_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    

class ManagedStorageTest extends ConfigStorageTestBase implements StorageManagerInterface {

  /** * {@inheritdoc} */
  public function getStorage() {
    // We return a new storage every time to make sure the managed storage     // only calls this once and retains the configuration by itself.     return new MemoryStorage();
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->storage = new ManagedStorage($this);
  }

  /** * {@inheritdoc} */

class MemoryStorageTest extends ConfigStorageTestBase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->storage = new MemoryStorage();
  }

  /** * {@inheritdoc} */
  protected function read($name) {
    return $this->storage->read($name);
  }

  /** * {@inheritdoc} */
'system.site',
    ];
    $this->assertEquals($expected$this->storageComparer->getChangelist('update'));
    $this->assertEmpty($this->storageComparer->getChangelist('create'));
    $this->assertEmpty($this->storageComparer->getChangelist('delete'));
  }

  /** * @covers ::createChangelist */
  public function testDifferentCollections() {
    $source = new MemoryStorage();
    $target = new MemoryStorage();

    $this->generateRandomData($source, 's');
    $this->generateRandomData($target, 't');

    // Use random collections for source and target.     $collections = $source->getAllCollectionNames();
    $source = $source->createCollection($collections[array_rand($collections)]);
    $collections = $target->getAllCollectionNames();
    $target = $target->createCollection($collections[array_rand($collections)]);

    
Home | Imprint | This part of the site doesn't use cookies.