You are here

protected function ConfigStorageTestTrait::getExportStorage in Config Filter 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ConfigStorageTestTrait.php \Drupal\Tests\config_filter\Kernel\ConfigStorageTestTrait::getExportStorage()

Trigger the export transformation and return its result.

Return value

\Drupal\Core\Config\StorageInterface The storage with the config to be exported.

1 call to ConfigStorageTestTrait::getExportStorage()
ExampleStorageKernelTest::testExampleExport in tests/src/Kernel/ExampleStorageKernelTest.php
Example to test export.

File

tests/src/Kernel/ConfigStorageTestTrait.php, line 94

Class

ConfigStorageTestTrait
Trait to easily test import and export of config by comparing storages.

Namespace

Drupal\Tests\config_filter\Kernel

Code

protected function getExportStorage() : StorageInterface {
  $manager = new ExportStorageManager($this->container
    ->get('config.storage'), $this->container
    ->get('database'), $this->container
    ->get('event_dispatcher'), new NullLockBackend());

  // This is the same essentially as the config.storage.export service
  // but the container doesn't cache it so we can access it several times
  // with updated config in the same test and trigger the transformation anew.
  $unfiltered = $manager
    ->getStorage();

  // For config filter 1.x we need to trigger the write filters.
  // Set up a filtered storage with the sync storage filters.
  $memory = new MemoryStorage();

  // Add the sync config so that filters can read from it.
  $this
    ->copyConfig($this->container
    ->get('config.storage.sync'), $memory);

  // Create a filtered storage.
  $filtered = $this->container
    ->get('config_filter.storage_factory')
    ->getFilteredStorage($memory, [
    'config.storage.sync',
  ]);

  // Then write the core export storage to this new storage.
  $this
    ->copyConfig($unfiltered, $filtered);
  return $memory;
}