public function ConfigDiffTest::testCollectionDiff in Drupal 9
Same name and namespace in other branches
- 8 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\ConfigCode
public function testCollectionDiff() {
/** @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',
]);
}