function ConfigDiffTest::testCollectionDiff

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php \Drupal\KernelTests\Core\Config\ConfigDiffTest::testCollectionDiff()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php \Drupal\KernelTests\Core\Config\ConfigDiffTest::testCollectionDiff()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php \Drupal\KernelTests\Core\Config\ConfigDiffTest::testCollectionDiff()

Tests calculating the difference between two sets of config collections.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php, line 111

Class

ConfigDiffTest
Calculating the difference between two sets of configuration.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testCollectionDiff() : void {
    
    /** @var \Drupal\Core\Config\StorageInterface $active */
    $active = $this->container
        ->get('config.storage');
    
    /** @var \Drupal\Core\Config\StorageInterface $sync */
    $sync = $this->container
        ->get('config.storage.sync');
    $active_test_collection = $active->createCollection('test');
    $sync_test_collection = $sync->createCollection('test');
    $config_name = 'config_test.test';
    $data = [
        'foo' => 'bar',
    ];
    $active->write($config_name, $data);
    $sync->write($config_name, $data);
    $active_test_collection->write($config_name, $data);
    $sync_test_collection->write($config_name, [
        'foo' => 'baz',
    ]);
    // Test the fields match in the default collection diff.
    $diff = \Drupal::service('config.manager')->diff($active, $sync, $config_name);
    $edits = $diff->getEdits();
    $this->assertEquals('copy', $edits[0]->type, 'The first item in the diff is a copy.');
    $this->assertCount(1, $edits, 'There is one item in the diff');
    // Test that the differences are detected when diffing the collection.
    $diff = \Drupal::service('config.manager')->diff($active, $sync, $config_name, NULL, 'test');
    $edits = $diff->getEdits();
    $this->assertYamlEdit($edits, 'foo', 'change', [
        'foo: bar',
    ], [
        'foo: baz',
    ]);
}

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