Browse Source

Relax types on StaticConfigTrait::setConfig()

Fixes #17212
Mark Story 2 years ago
parent
commit
2edc7ad9fc
2 changed files with 15 additions and 2 deletions
  1. 2 2
      src/Core/StaticConfigTrait.php
  2. 13 0
      tests/TestCase/Core/StaticConfigTraitTest.php

+ 2 - 2
src/Core/StaticConfigTrait.php

@@ -68,12 +68,12 @@ trait StaticConfigTrait
      * ```
      *
      * @param array<string, mixed>|string $key The name of the configuration, or an array of multiple configs.
-     * @param object|array<string, mixed>|null $config An array of name => configuration data for adapter.
+     * @param mixed $config The value for the config key. Generally an array of name => configuration data for adapter.
      * @throws \BadMethodCallException When trying to modify an existing config.
      * @throws \LogicException When trying to store an invalid structured config array.
      * @return void
      */
-    public static function setConfig(array|string $key, object|array|null $config = null): void
+    public static function setConfig(array|string $key, mixed $config = null): void
     {
         if ($config === null) {
             if (!is_array($key)) {

+ 13 - 0
tests/TestCase/Core/StaticConfigTraitTest.php

@@ -69,6 +69,19 @@ class StaticConfigTraitTest extends TestCase
         $className::parseDsn(['url' => 'http://:80']);
     }
 
+    public function testSetConfigValues(): void
+    {
+        $className = get_class($this->subject);
+        $className::setConfig('foo', true);
+
+        $result = $className::getConfigOrFail('foo');
+        $this->assertTrue($result);
+
+        $className::setConfig('bar', 'value');
+        $result = $className::getConfigOrFail('bar');
+        $this->assertSame('value', $result);
+    }
+
     public function testGetConfigOrFail(): void
     {
         $className = get_class($this->subject);