Score:5

How do I import a sync config file into my Kernel unit test?

in flag

How do I import a sync config file into my Kernel unit test ?

Specifically, I have some REST resources in files config/sync/rest.resource.foo.yml,config/sync/rest.resource.bar.yml

At present, when I run \Drupal::service('router.builder')->rebuild() in my setUp() function, it does not add in the routes for these resources, so when I make GET requests to them in the tests, I get 404.

I don't want to import all of the config for my Drupal site into the unit test, just the REST resources.

miststudent2011 avatar
fr flag
I too had a similar requirement and searched for solutions. Related discussions in Drupal Slack. https://drupal.slack.com/archives/C223PR743/p1643094724029400?thread_ts=1643094724.029400&cid=C223PR743
Monkeybrain avatar
in flag
I am having trouble joining Drupal Slack. Would it be possible for you to summarise any of the suggestions made ?
miststudent2011 avatar
fr flag
TLDR; try ` $this->installConfig(['system', 'field', 'datetime','my_module']);` in setup method in kernel test.
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.