How to save configs in BrowserTestBase? In a functional test I try to test a functionality after changing the module configuration:

public function setUp() {
  parent::setUp();
  ...
  $config = \Drupal::configFactory()-&gt;getEditable('move_file.settings');
  $config-&gt;set('vocabulary', 'tags');
  $config-&gt;save();
  ...
}


The tested functionality is located primarily in MoveFileService.php. But the service does not see the configs. When I debug the configs directly in the service, then I get:

public function __construct(ConfigFactory $config_factory, LoggerChannelFactoryInterface $logger_factory) {
    $this-&gt;config = $config_factory-&gt;get('move_file.settings');
    $this-&gt;logger = $logger_factory-&gt;get('move_file');
}

public static function create(ContainerInterface $container) {
    return new static(
    $container-&gt;get('config.factory'),
    $container-&gt;get('logger.factory')
    );
}

public function configsAreSet() {
    ...
    fwrite(STDOUT, "Settings: {$this-&gt;config-&gt;get('vocabulary')}\n");
    // Returns: Settings:
    // The configuration is null.

    $config = \Drupal::service('config.factory')-&gt;getEditable('move_file.settings');
    fwrite(STDOUT, "Settings: {$config-&gt;get('vocabulary')}\n");
    // Returns: Settings: tags
    // This returns the expected value. But the good practice is to use the dependency injection.
    ...
}


How can I save the config in the setUp() method of the functional test, so that the service can get the saved configuration, when the test is running?
I have found, that the problem was caused, that in the setUp() method of the test class, was at first used the $this->drupalCreateNode([...]) method and then were created the settings. After moving the $config->set(...) method at the beginning of the setUp() method, works everything perfect.

See:


The test class
Test results