function ConfigCRUDTest::testValueValidation

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php \Drupal\KernelTests\Core\Config\ConfigCRUDTest::testValueValidation()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php \Drupal\KernelTests\Core\Config\ConfigCRUDTest::testValueValidation()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php \Drupal\KernelTests\Core\Config\ConfigCRUDTest::testValueValidation()

Tests the validation of configuration object values.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php, line 245

Class

ConfigCRUDTest
Tests CRUD operations on configuration objects.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testValueValidation() {
    // Verify that setData() will catch dotted keys.
    try {
        $this->config('namespace.object')
            ->setData([
            'key.value' => 12,
        ])
            ->save();
        $this->fail('Expected ConfigValueException was thrown from setData() for value with dotted keys.');
    } catch (\Exception $e) {
        $this->assertInstanceOf(ConfigValueException::class, $e);
    }
    // Verify that set() will catch dotted keys.
    try {
        $this->config('namespace.object')
            ->set('foo', [
            'key.value' => 12,
        ])
            ->save();
        $this->fail('Expected ConfigValueException was thrown from set() for value with dotted keys.');
    } catch (\Exception $e) {
        $this->assertInstanceOf(ConfigValueException::class, $e);
    }
}

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