SchemaConfigListenerTestTrait.php in Drupal 9
File
core/tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php
View source
<?php
namespace Drupal\Tests\Traits\Core\Config;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
trait SchemaConfigListenerTestTrait {
public function testConfigSchemaChecker() {
$message = 'Expected SchemaIncompleteException thrown';
try {
$this
->config('config_schema_test.schemaless')
->set('foo', 'bar')
->save();
$this
->fail($message);
} catch (SchemaIncompleteException $e) {
$this
->assertEquals('No schema for config_schema_test.schemaless', $e
->getMessage());
}
$message = 'Unexpected SchemaIncompleteException thrown';
$config = $this
->config('config_test.types')
->set('int', 10);
try {
$config
->save();
} catch (SchemaIncompleteException $e) {
$this
->fail($message);
}
$message = 'Unexpected SchemaIncompleteException thrown';
$config = $this
->config('config_test.types')
->set('int', '10');
$config
->get('int');
try {
$config
->save();
} catch (SchemaIncompleteException $e) {
$this
->fail($message);
}
$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
->assertEquals('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());
}
}
}