trait ConfigTestTrait

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/ConfigTestTrait.php \Drupal\Tests\ConfigTestTrait
  2. 10 core/tests/Drupal/Tests/ConfigTestTrait.php \Drupal\Tests\ConfigTestTrait
  3. 11.x core/tests/Drupal/Tests/ConfigTestTrait.php \Drupal\Tests\ConfigTestTrait

Provides helper methods to deal with config system objects in tests.

Hierarchy

2 files declare their use of ConfigTestTrait
KernelTestBase.php in core/tests/Drupal/KernelTests/KernelTestBase.php
TestBase.php in core/modules/simpletest/src/TestBase.php

File

core/tests/Drupal/Tests/ConfigTestTrait.php, line 13

Namespace

Drupal\Tests
View source
trait ConfigTestTrait {
    use StorageCopyTrait;
    
    /**
     * Returns a ConfigImporter object to import test configuration.
     *
     * @return \Drupal\Core\Config\ConfigImporter
     *   The config importer object.
     */
    protected function configImporter() {
        if (!$this->configImporter) {
            // Set up the ConfigImporter object for testing.
            $storage_comparer = new StorageComparer($this->container
                ->get('config.storage.sync'), $this->container
                ->get('config.storage'));
            $this->configImporter = new ConfigImporter($storage_comparer, $this->container
                ->get('event_dispatcher'), $this->container
                ->get('config.manager'), $this->container
                ->get('lock'), $this->container
                ->get('config.typed'), $this->container
                ->get('module_handler'), $this->container
                ->get('module_installer'), $this->container
                ->get('theme_handler'), $this->container
                ->get('string_translation'), $this->container
                ->get('extension.list.module'));
        }
        // Always recalculate the changelist when called.
        return $this->configImporter
            ->reset();
    }
    
    /**
     * Copies configuration objects from source storage to target storage.
     *
     * @param \Drupal\Core\Config\StorageInterface $source_storage
     *   The source config storage service.
     * @param \Drupal\Core\Config\StorageInterface $target_storage
     *   The target config storage service.
     */
    protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) {
        static::replaceStorageContents($source_storage, $target_storage);
    }

}

Members

Title Sort descending Modifiers Object type Summary
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.

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