SchemaCheckTestTrait.php in Drupal 10
File
core/tests/Drupal/Tests/SchemaCheckTestTrait.php
View source
<?php
namespace Drupal\Tests;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Config\Schema\SchemaCheckTrait;
trait SchemaCheckTestTrait {
use SchemaCheckTrait;
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}");
}
public function assertConfigSchemaByName($config_name) {
$config = $this
->config($config_name);
$this
->assertConfigSchema(\Drupal::service('config.typed'), $config
->getName(), $config
->get());
}
}