trait SchemaConfigListenerTestTrait
Same name in other branches
- 9 core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php \Drupal\Tests\Traits\Core\Config\SchemaConfigListenerTestTrait
- 10 core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php \Drupal\Tests\Traits\Core\Config\SchemaConfigListenerTestTrait
- 11.x core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php \Drupal\Tests\Traits\Core\Config\SchemaConfigListenerTestTrait
Adds a test for the configuration schema checker use in tests.
Hierarchy
- trait \Drupal\Tests\Traits\Core\Config\SchemaConfigListenerTestTrait
2 files declare their use of SchemaConfigListenerTestTrait
- SchemaConfigListenerTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Config/ SchemaConfigListenerTest.php - SchemaConfigListenerTest.php in core/
tests/ Drupal/ FunctionalTests/ Core/ Config/ SchemaConfigListenerTest.php
File
-
core/
tests/ Drupal/ Tests/ Traits/ Core/ Config/ SchemaConfigListenerTestTrait.php, line 10
Namespace
Drupal\Tests\Traits\Core\ConfigView source
trait SchemaConfigListenerTestTrait {
/**
* Tests \Drupal\Core\Config\Development\ConfigSchemaChecker.
*/
public function testConfigSchemaChecker() {
// Test a non-existing schema.
$message = 'Expected SchemaIncompleteException thrown';
try {
$this->config('config_schema_test.schemaless')
->set('foo', 'bar')
->save();
$this->fail($message);
} catch (SchemaIncompleteException $e) {
$this->pass($message);
$this->assertEqual('No schema for config_schema_test.schemaless', $e->getMessage());
}
// Test a valid schema.
$message = 'Unexpected SchemaIncompleteException thrown';
$config = $this->config('config_test.types')
->set('int', 10);
try {
$config->save();
$this->pass($message);
} catch (SchemaIncompleteException $e) {
$this->fail($message);
}
// Test a valid schema, where the value is accessed before saving. Ensures
// that overridden data is correctly reset after casting.
$message = 'Unexpected SchemaIncompleteException thrown';
$config = $this->config('config_test.types')
->set('int', '10');
$config->get('int');
try {
$config->save();
$this->pass($message);
} catch (SchemaIncompleteException $e) {
$this->fail($message);
}
// Test an invalid schema.
$message = 'Expected SchemaIncompleteException thrown';
$config = $this->config('config_test.types')
->set('foo', 'bar')
->set('array', 1);
try {
$config->save();
$this->fail($message);
} catch (SchemaIncompleteException $e) {
$this->pass($message);
$this->assertEqual('Schema errors for config_test.types with the following errors: config_test.types:array variable type is integer but applied schema class is Drupal\\Core\\Config\\Schema\\Sequence, config_test.types:foo missing schema', $e->getMessage());
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
SchemaConfigListenerTestTrait::testConfigSchemaChecker | public | function | Tests \Drupal\Core\Config\Development\ConfigSchemaChecker. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.