2

I got an existing Drupal 8.2.x project with existing unit tests. When I run a sample unit test, I get the error (real module name redacted):

No schema for my_module.global

This doesn't seem to be related to the my_module.schema.yml file, or any DB schema that I can tell. Drilling down, I got this output for the $definition variable in \Drupal\Core\Config\TypedConfigManager.php, which the unit test calls up (among others):

array (
  'label' => 'Undefined',
  'class' => 'Drupal\\Core\\Config\\Schema\\Undefined',
  'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
  'type' => 'undefined',
)

For core modules the class is Drupal\\Core\\Config\\Schema\\Mapping. Note that the error complains about a schema for my_module.global, which is one of the YAML config files for this module (can't tell how else it's related).

The question is, what does this schema mean exactly, and where do I set it for my module?

5

Turns out that it is related to the my_module.schema.yml. Looks like every YAML file under my_module/config/install must have a corresponding schema in the my_module.schema.yml file in order to set up a unit test, even if this is not actually required for the module to work. It needs to look something like this (assuming the config/install file name is my_module.global.yml):

my_module.global:
  type: mapping
  label: 'My label'
  mapping:
    property:
      type: text
      label: 'Property label'

If unsure which properties need to go there, running the unit test without them will give a list as part of the error. I'm sure there is a better way to find this, but that's the way I found so far.

Edit – the whole schema verification mechanism can be turned off: In drupal/core/lib/Drupal/Core/Test/TestSetupTrait.php, $strictConfigSchema needs to be set to FALSE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.