You are here

class ConfigDiffTransformerTest in Update helper 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/ConfigDiffTransformerTest.php \Drupal\Tests\update_helper\Unit\ConfigDiffTransformerTest

Automated tests for the 'update_helper.config_diff_transformer' service.

@group update_helper

Hierarchy

Expanded class hierarchy of ConfigDiffTransformerTest

File

tests/src/Unit/ConfigDiffTransformerTest.php, line 13

Namespace

Drupal\Tests\update_helper\Unit
View source
class ConfigDiffTransformerTest extends UnitTestCase {

  /**
   * Test transforming of configuration to array of strings.
   *
   * @param array $config
   *   Configuration array that should be transformed.
   * @param array $expected
   *   Expected result of "transform" execution.
   *
   * @dataProvider transformDataProvider
   */
  public function testTransform(array $config, array $expected) {
    $transformer = new ConfigDiffTransformer();
    $result = $transformer
      ->transform($config);
    $this
      ->assertEquals($expected, $result);
  }

  /**
   * Test transforming of configuration to array of strings.
   *
   * @param array $expected
   *   Expected result of "reverseTransform" execution.
   * @param array $transformedConfig
   *   Transformed configuration array that should be reversibly transformed.
   *
   * @dataProvider transformDataProvider
   */
  public function testReverseTransform(array $expected, array $transformedConfig) {
    $transformer = new ConfigDiffTransformer();
    $result = $transformer
      ->reverseTransform($transformedConfig);
    $this
      ->assertEquals($expected, $result);
  }

  /**
   * Data provider for transform and reverseTransform methods test.
   *
   * @return array
   *   Return test cases for testProcessRiddleResponse.
   */
  public function transformDataProvider() {
    return [
      [
        [],
        [],
      ],
      [
        [
          'uuid' => '1234-5678-90',
          'id' => 'test.config.id',
          'short_text' => 'en',
          'long_text' => 'Automated tests for the ConfigDiffTransformer service.',
          'true_value' => TRUE,
          'false_value' => FALSE,
          'nested_array' => [
            'flat_array' => [
              'value2',
              'value1',
              'value3',
            ],
            'custom_key' => 'value',
          ],
          'empty_array' => [],
          'empty_string' => '',
          'null_value' => NULL,
        ],
        [
          'uuid : s:12:"1234-5678-90";',
          'id : s:14:"test.config.id";',
          'short_text : s:2:"en";',
          'long_text : s:54:"Automated tests for the ConfigDiffTransformer service.";',
          'true_value : b:1;',
          'false_value : b:0;',
          'nested_array',
          'nested_array::flat_array',
          'nested_array::flat_array::- : s:6:"value2";',
          'nested_array::flat_array::- : s:6:"value1";',
          'nested_array::flat_array::- : s:6:"value3";',
          'nested_array::custom_key : s:5:"value";',
          'empty_array : a:0:{}',
          'empty_string : s:0:"";',
          'null_value : N;',
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigDiffTransformerTest::testReverseTransform public function Test transforming of configuration to array of strings.
ConfigDiffTransformerTest::testTransform public function Test transforming of configuration to array of strings.
ConfigDiffTransformerTest::transformDataProvider public function Data provider for transform and reverseTransform methods test.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340