2

After creating a custom configuration for my module "module_name.settings.yml" simpletest fails with this message:

InvalidArgumentException: Invalid database prefix: in Drupal\Core\Test\TestDatabase->__construct() (line 81 of /path/to/installation/core/lib/Drupal/Core/Test/TestDatabase.php)

I reinstalled my module and everything works. I load the configuration with the following code.

$config = \Drupal::config('module_name.settings');
$base = $config->get('module_name.variable');

Still, I can't run my tests. If I remove the content from my configuration, tests run again. I'm using Drupal 8.3.4, Apache 2.4.18, PHP 7.0.8, and MariaDB 10.1.25.

8
  • What modules are listed for installing? I would bet a million dollars it is because one of the modules is missing a .schema.yml file under the config/schema dir.
    – Kevin
    Commented Jul 28, 2017 at 18:37
  • @Kevin I don't think so, I can install my module. And if I remove the config file run tests properly. Commented Jul 28, 2017 at 18:58
  • Exactly. Because you removed the config file. I ran into the exact same thing earlier this year and patched Menu Breadcrumb to fix the error. Other modules missing a schema.yml file were also patched to fix this error. The error above is very misleading because it is not specific.
    – Kevin
    Commented Jul 28, 2017 at 19:07
  • See: drupal.org/node/2848879 and drupal.stackexchange.com/questions/226501/…
    – Kevin
    Commented Jul 28, 2017 at 19:09
  • 1
    @Kevin I think I own you a billion dollars now, you was right. A .schema.yml file was missing. Thanks for your time. Commented Jul 28, 2017 at 19:57

1 Answer 1

4

Since your module provides a settings.yml file, it must also provide a mymodule.schema.yml file describing the config object that stores the settings.

The real error pertains to something along these lines, and not a database error:

The test did not complete due to a fatal error.
Exception Uncaught e ConfigSchemaCheck   86 Drupal\Core\Config\Testing\ConfigSc
    Drupal\Core\Config\Schema\SchemaIncompleteException: No schema for
    MODULENAME.settings in
    Drupal\Core\Config\Testing\ConfigSchemaChecker->onConfigSave() (line 86
    of
    /var/www/docroot/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php).

By providing a schema.yml file, clearing cache and re-running the tests this should resolve itself.

Related:

You have to be careful of this one, because any contrib module that provides a settings.yml without a matching schema will throw the same error. It is confusing because you can install the module in your main application, but when you install it with a test, it will error out.

It will be easy to narrow down which ones, because it will be one that is listed in your required modules var (protected static $modules = [...]) which is how I stumbled upon the Menu Breadcrumb issue I mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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