Score:1

functional test: Schema errors but Schema is correct

hm flag

I have a settings form in my custom module and functional test of this form.

I added new field to form

$form['unblockable_roles'] = [
  '#type' => 'checkboxes',
  '#title' => $this->t('Users cannot block another users with these roles'),
  '#options' => $roles_options,
  '#default_value' => $config->get('unblockable_roles') ?: [],
];

Updated schema file:

mymodule.settings:
  type: config_object
  label: 'My module settings'
  mapping:
    allowed_roles:
      label: 'Allow send messages for these roles'
      type: sequence
      sequence:
        type: string
        label: 'Role ID'
    unblockable_roles:
      label: 'Users cannot block another users with these roles'
      type: sequence
      sequence:
        type: string
        label: 'Role ID'

The "config inspector" module has no errors with new field schema, but phpunit says:

"Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for mymodule.settings with the following errors: mymodule.settings:unblockable_roles missing schema in Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line 94 of core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php)."

The same field "allowed_roles" works fine.

I cleared caches, stop-start docker, but without success.

if I use "protected $strictConfigSchema = FALSE;" my test is success. Form values successfully saved.

Score:1
bf flag

I have had this error before when writing functional unit tests, for me it wasn't that the schema was wrong in the custom module settings it was that the schema was wrong and/or missing in the config install files so needed to either change that to match the module or change the module to match what is in config install files. or import the config installs into your module.

Score:0
hm flag

My fault. I use this patch to speedup functional tests. It cause my problem.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.