Remove \Drupal\Tests\cdn\Unit\File\FileUrlGeneratorTest::getConfigFactoryStub() once the CDN module can require Drupal 8.5
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #2934643. --> Reported by: [wim leers](https://www.drupal.org/user/99777) >>> <p>Quoting myself from <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/drupal/issues/2862248" title="Status: Closed (fixed)">#2862248: UnitTestCase::getConfigFactoryStub() doesn't accept dotted keys</a></span>:</p> <blockquote><p> Hah! While scanning the RTBC queue, this one caught my eye.</p> <p>I also ran into this in #2708787, in the CDN contrib module that I maintain. I added a work-around in <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/cdn/-/work_items/2708787" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/cdn/-/work_items/2708787</a></span>, but then forgot to report it back to the Drupal core issue queue.</p> <p>I overrode <code>UnitTestCase::getConfigFactoryStub()</code> in my unit test, with the following interdiff:</p> <pre>diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php<br>index 58173e5..030b5e4 100644<br>--- a/core/tests/Drupal/Tests/UnitTestCase.php<br>+++ b/core/tests/Drupal/Tests/UnitTestCase.php<br>@@ -111,20 +111,24 @@ public function getConfigFactoryStub(array $configs = []) {<br>&nbsp;&nbsp;&nbsp;&nbsp; $config_editable_map = [];<br>&nbsp;&nbsp;&nbsp;&nbsp; // Construct the desired configuration object stubs, each with its own<br>&nbsp;&nbsp;&nbsp;&nbsp; // desired return map.<br>-&nbsp;&nbsp;&nbsp; foreach ($configs as $config_name =&gt; $config_values) {<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map = [];<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($config_values as $key =&gt; $value) {<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map[] = [$key, $value];<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Also allow to pass in no argument.<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $map[] = ['', $config_values];<br>+&nbsp;&nbsp;&nbsp; foreach ($configs as $config_name =&gt; $map) {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $get = function ($key) use ($map) {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $parts = explode('.', $key);<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (count($parts) == 1) {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return isset($map[$key]) ? $map[$key] : NULL;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $value = NestedArray::getValue($map, $parts, $key_exists);<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $key_exists ? $value : NULL;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $immutable_config_object = $this-&gt;getMockBuilder('Drupal\Core\Config\ImmutableConfig')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;disableOriginalConstructor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;getMock();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $immutable_config_object-&gt;expects($this-&gt;any())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;method('get')<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;will($this-&gt;returnValueMap($map));<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;willReturnCallback($get);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $config_get_map[] = [$config_name, $immutable_config_object];<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mutable_config_object = $this-&gt;getMockBuilder('Drupal\Core\Config\Config')<br>@@ -132,7 +136,7 @@ public function getConfigFactoryStub(array $configs = []) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;getMock();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mutable_config_object-&gt;expects($this-&gt;any())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;method('get')<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;will($this-&gt;returnValueMap($map));<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;willReturnCallback($get);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $config_editable_map[] = [$config_name, $mutable_config_object];<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; // Construct a config factory with the array of configuration object stubs</pre><p>And had this docblock for my override:</p> <pre>&nbsp; /**<br>&nbsp;&nbsp; * {@inheritdoc}<br>&nbsp;&nbsp; *<br>&nbsp;&nbsp; * Overridden, because the way ImmutableConfig::get() is mocked, does not<br>&nbsp;&nbsp; * match the actual implementation, which then causes tests to fail.<br>&nbsp;&nbsp; */</pre><p>Glad to see this being solved in Drupal core! &#127881; </p></blockquote> > Related issue: [Issue #2708787](https://www.drupal.org/node/2708787) > Related issue: [Issue #2862248](https://www.drupal.org/node/2862248)
issue