function MappingTest::testInvalidMappingKeyDefinition

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Config/Schema/MappingTest.php \Drupal\KernelTests\Config\Schema\MappingTest::testInvalidMappingKeyDefinition()

@testWith [false, 42, "The mapping definition at `foobar` is invalid: its `invalid` key contains a integer. It must be an array."]
[false, 10.2, "The mapping definition at `foobar` is invalid: its `invalid` key contains a double. It must be an array."]
[false, "type", "The mapping definition at `foobar` is invalid: its `invalid` key contains a string. It must be an array."]
[false, false, "The mapping definition at `foobar` is invalid: its `invalid` key contains a boolean. It must be an array."]
[true, 42, "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a integer. It must be an array."]
[true, 10.2, "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a double. It must be an array."]
[true, "type", "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a string. It must be an array."]
[true, false, "The mapping definition at `my_module.settings:foobar` is invalid: its `invalid` key contains a boolean. It must be an array."]

File

core/tests/Drupal/KernelTests/Config/Schema/MappingTest.php, line 525

Class

MappingTest
@coversDefaultClass \Drupal\Core\Config\Schema\Mapping[[api-linebreak]] @group Config

Namespace

Drupal\KernelTests\Config\Schema

Code

public function testInvalidMappingKeyDefinition(bool $has_parent, mixed $invalid_key_definition, string $expected_message) : void {
  $definition = new MapDataDefinition([
    'type' => 'mapping',
    'mapping' => [
      'valid' => [
        'type' => 'boolean',
        'label' => 'This is a valid key-value pair in this mapping',
      ],
      'invalid' => $invalid_key_definition,
    ],
  ]);
  $parent = NULL;
  if ($has_parent) {
    $parent = new Mapping(new MapDataDefinition([
      'type' => 'mapping',
      'mapping' => [],
    ]), 'my_module.settings');
  }
  $this->expectException(\LogicException::class);
  $this->expectExceptionMessage($expected_message);
  new Mapping($definition, 'foobar', $parent);
}

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