You are here

class ConfigPatchTest in Configuration Split 2.0.x

Test patch creation and merging without sorting.

@group config_split

Hierarchy

  • class \Drupal\Tests\config_split\Unit\ConfigPatchTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of ConfigPatchTest

File

tests/src/Unit/ConfigPatchTest.php, line 16

Namespace

Drupal\Tests\config_split\Unit
View source
class ConfigPatchTest extends TestCase {

  /**
   * The patch merge service under test.
   *
   * @var \Drupal\config_split\Config\ConfigPatchMerge
   */
  protected $patchMerge;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $this->patchMerge = new ConfigPatchMerge($this
      ->prophesize(ConfigSorter::class)
      ->reveal());
  }

  /**
   * Test some simplified config patch and merge workflow.
   */
  public function testSimpleMergeExample() {

    // This is a much simplified version of some config. We use the complete
    // split to split off the module 'a' but we also partially split the config.
    // This is the active config.
    $active = [
      'dependencies' => [
        'a',
        'b',
      ],
      'something' => 'A',
    ];

    // This is the config in the sync storage before changes were made.
    $sync = [
      'dependencies' => [
        'a',
        'b',
      ],
      'something_else' => 'B',
    ];

    // This is the config which was updated by removing 'a'.
    // The patch already created by the complete split would contain this.
    $updated = [
      'dependencies' => [
        'b',
      ],
      'something' => 'A',
    ];

    // This is what we expect to be exported at then end.
    $expected = [
      'dependencies' => [
        'b',
      ],
      'something_else' => 'B',
    ];

    // This is the patch which is already in the split storage.
    $patch1 = $this->patchMerge
      ->createPatch($active, $updated);

    // This is the "fixed" sync storage so that we can create a merged patch.
    $fixed = $this->patchMerge
      ->mergePatch($sync, $patch1);

    // This is the patch we want to export.
    $patch2 = $this->patchMerge
      ->createPatch($active, $fixed);

    // This is what we export.
    $export = $this->patchMerge
      ->mergePatch($active, $patch2);
    self::assertEquals($expected, $export);

    // When doing the reverse we expect it to work again.
    $import = $this->patchMerge
      ->mergePatch($sync, $patch2
      ->invert());
    self::assertEquals($active, $import);
    $import = $this->patchMerge
      ->mergePatch($export, $patch2
      ->invert());
    self::assertEquals($active, $import);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigPatchTest::$patchMerge protected property The patch merge service under test.
ConfigPatchTest::setUp public function
ConfigPatchTest::testSimpleMergeExample public function Test some simplified config patch and merge workflow.