trait SchemaCheckTestTrait in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait
- 10 core/tests/Drupal/Tests/SchemaCheckTestTrait.php \Drupal\Tests\SchemaCheckTestTrait
Provides a class for checking configuration schema.
Hierarchy
- trait \Drupal\Tests\SchemaCheckTestTrait uses SchemaCheckTrait
39 files declare their use of SchemaCheckTestTrait
- BlockConfigSchemaTest.php in core/
modules/ block/ tests/ src/ Kernel/ BlockConfigSchemaTest.php - ConfigImportAllTest.php in core/
modules/ config/ tests/ src/ Functional/ ConfigImportAllTest.php - DateTimeSchemaTest.php in core/
modules/ datetime/ tests/ src/ Kernel/ Views/ DateTimeSchemaTest.php - DefaultConfigTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Config/ DefaultConfigTest.php - EntityReferenceFieldDefaultValueTest.php in core/
modules/ field/ tests/ src/ Functional/ EntityReference/ EntityReferenceFieldDefaultValueTest.php
File
- core/
tests/ Drupal/ Tests/ SchemaCheckTestTrait.php, line 11
Namespace
Drupal\TestsView source
trait SchemaCheckTestTrait {
use SchemaCheckTrait;
/**
* Asserts the TypedConfigManager has a valid schema for the configuration.
*
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The TypedConfigManager.
* @param string $config_name
* The configuration name.
* @param array $config_data
* The configuration data.
*/
public function assertConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) {
$check = $this
->checkConfigSchema($typed_config, $config_name, $config_data);
$message = '';
if ($check === FALSE) {
$message = 'Error: No schema exists.';
}
elseif ($check !== TRUE) {
$this
->assertIsArray($check, "The config schema check errors should be in the form of an array.");
$message = "Errors:\n";
foreach ($check as $key => $error) {
$message .= "Schema key {$key} failed with: {$error}\n";
}
}
$this
->assertTrue($check, "There should be no errors in configuration '{$config_name}'. {$message}");
}
/**
* Asserts configuration, specified by name, has a valid schema.
*
* @param string $config_name
* The configuration name.
*/
public function assertConfigSchemaByName($config_name) {
$config = $this
->config($config_name);
$this
->assertConfigSchema(\Drupal::service('config.typed'), $config
->getName(), $config
->get());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchemaCheckTestTrait:: |
public | function | Asserts the TypedConfigManager has a valid schema for the configuration. | |
SchemaCheckTestTrait:: |
public | function | Asserts configuration, specified by name, has a valid schema. | |
SchemaCheckTrait:: |
protected | property | The configuration object name under test. | |
SchemaCheckTrait:: |
protected | property | The config schema wrapper object for the configuration object under test. | |
SchemaCheckTrait:: |
public | function | Checks the TypedConfigManager has a valid schema for the configuration. | |
SchemaCheckTrait:: |
protected | function | Helper method to check data type. |