Kernel tests: Url toString with language option In a Kernel test I need to test the result of an url object per language. But the test doesn't consider the language settings.
Example:
public function register(ContainerBuilder $container) {
    parent::register($container);

    $language = Language::$defaultValues;
    $language['id'] = 'de';
    $language['name'] = 'German';
    $container-&gt;setParameter('language.default_values', $language);
}

protected function setUp() {
    parent::setUp();

    ConfigurableLanguage::createFromLangcode('fr')-&gt;save();
    ConfigurableLanguage::createFromLangcode('it')-&gt;save();
}

public function testUrls() {
    $languageManager = $this-&gt;container-&gt;get('language_manager');
    print_r($languageManager-&gt;getLanguages());

    $url = Url::fromRoute('&lt;front&gt;');
    $url-&gt;setOption('language', $languageManager-&gt;getLanguage('fr'));
    print_r($url-&gt;toString());
}

Output:
Array
(
    [de]
    [fr]
    [it]
)

# Output of toString()
/

The output of toString should be /fr instead of /
Addendum:
I discovered that the \Drupal\language\HttpKernel\PathProcessorLanguage outbound processor is missing, when UrlGenerator::processPath() is called from the Kernel test. Therefore, I registered it in the Kernel test's register method, but that doesn't solve the problem.
Solution
I could solve it by register the PathProcessorLanguage class and add the language.types and language.negotiation config.
public function register(ContainerBuilder $container) {
  parent::register($container);

  // Define the default language.
  $language = Language::$defaultValues;
  $language['id'] = 'de';
  $language['name'] = 'German';
  $container-&gt;setParameter('language.default_values', $language);

  // Register PathProcessorLanguage.
  $container-&gt;register('path_processor_language', PathProcessorLanguage::class)
    -&gt;addTag('path_processor_outbound', ['priority' =&gt; 100])
    -&gt;addArgument(new Reference('config.factory'))
    -&gt;addArgument(new Reference('language_manager'))
    -&gt;addArgument(new Reference('language_negotiator'))
    -&gt;addArgument(new Reference('current_user'))
    -&gt;addArgument(new Reference('language.config_subscriber'));
}

protected function setUp() {
  parent::setUp();

  // Add additional languages.
  ConfigurableLanguage::createFromLangcode('fr')-&gt;save();
  ConfigurableLanguage::createFromLangcode('it')-&gt;save();

  // Define language settings.
  $this-&gt;config('language.types')-&gt;setData([
    'configurable' =&gt; ['language_interface'],
    'negotiation' =&gt; [
      'language_interface' =&gt; [
        'enabled' =&gt; [
          LanguageNegotiationUrl::METHOD_ID =&gt; 0,
        ],
      ],
    ],
  ])-&gt;save();

  $languageKeys = array_keys($this-&gt;container-&gt;get('language_manager')-&gt;getLanguages());
  $this-&gt;config('language.negotiation')-&gt;setData([
    'url' =&gt; [
      'source' =&gt; LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
      'prefixes' =&gt; array_combine($languageKeys, $languageKeys),
    ],
  ])-&gt;save();
}

Addition
If you want to use/test path alias configs too, just register the AliasPathProcessor class...
public function register(ContainerBuilder $container) {
  parent::register($container);

  // ...

  $container-&gt;register('path_alias.path_processor', AliasPathProcessor::class)
      -&gt;addTag('path_processor_outbound', ['priority' =&gt; 300])
      -&gt;addArgument(new Reference('path_alias.manager'));

  //...
}

... and add the path alias entry for the specific language.
protected function setUp() {
  parent::setUp();

  // ...

  $pathAlias = PathAlias::create([
      'path' =&gt; '/foo',
      'alias' =&gt; '/bar',
      'langcode' =&gt; 'it',
    ]);
    $pathAlias-&gt;save();

  // ...
}