1

I write tests for a custom module using Drupal\simpletest\WebTestBase. I can not find a method, how to debug the configuration object.

I tried e.g. the following commands:

$config = \Drupal::config('mymodule.settings');

debug($config); // AJAX-HTTP-Error
debug(get_object_vars($config)); // Empty array
debug($config->getRawData()); // Empty array
debug($config->getOriginal()); // Empty array
dump($config); // AJAX-HTTP-Error
var_dump($config); // Needs extremely long time
ksm($config); // Nothing is shown
kint($config); // Nothing is shown
dpm($config); // ServiceNotFoundException
dpm($config->toArray()); // AJAX-HTTP-Error
dsm(get_object_vars($config)); // ServiceNotFoundException
print_r($config); // Needs extremely long time

The debug() command works fine for arrays and strings (and is nice integrated in the test report).

 debug($var, 'Label');
  • What are you expecting to be able to see in the config object? Bear in mind the storage is probably lazy; it's not like there's an array in there somewhere with every single config key and value in it, values are likely to be loaded when requested – Clive Apr 11 '17 at 11:57
  • I would like to see an array with all available settings. – Antonín Slejška Apr 11 '17 at 12:01
2

You can use Config::get(), for which:

If no key is specified, then the entire data array is returned.

e.g.

debug(\Drupal::config('mymodule.settings')->get());
  • Thanks. I have found, that also debug(\Drupal::config('mymodule.settings')->geRawDatat()); works. The problem is, that I receive from both an empty array. But it is some other problem. (When I use \Drupal::config('system.site'), then I receive correct array.) – Antonín Slejška Apr 11 '17 at 12:26

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.