I write tests for a form in a custom module using Drupal\simpletest\WebTestBase. I want to test, if the module settings are displayed in the configuration form. But the problem is, that I can not get the saved settings:
$config = $this->config('mymodule.settings');
debug($config->get(), 'Configuration object'); // Returns an empty array
I have found, that the same problem is e.g. in the demo module described in an article on Sitepoint, see: https://github.com/upchuk/d8-demo-modules/blob/master/demo/src/Tests/DemoTest.php#L59
E.g. $config->get('demo.email_address') returns always ''.
The tests seem to work well, but when I add debug($config->get()), then I also receive an empty array. It means, that all the test cases use empty variables and return false positive results.
I have also tried:
debug(\Drupal::config('mymodule.settings')->get()); // Empty array
debug(\Drupal::configFactory()->getEditable('mymodule.settings')->get()); // Empty array
debug(\Drupal::config('system.site')->get()); // Correct array with site settings
The module and the form are working correctly and all the settings are stored in the database.
static $modules =
array?