Browse Source

Backport isConfigured

Providing a name to configured() will be removed in 4.0. Backport the
new method so folks can get warnings/upgrade before 4.0

Refs #12323
Mark Story 7 years ago
parent
commit
02ceac049b
2 changed files with 42 additions and 4 deletions
  1. 19 0
      src/Core/Configure.php
  2. 23 4
      tests/TestCase/Core/ConfigureTest.php

+ 19 - 0
src/Core/Configure.php

@@ -260,12 +260,20 @@ class Configure
     /**
      * Gets the names of the configured Engine objects.
      *
+     * Checking if a specific engine has been configured with this method is deprecated.
+     * Use Configure::isConfigured() instead.
+     *
      * @param string|null $name Engine name.
      * @return array|bool Array of the configured Engine objects, bool for specific name.
      */
     public static function configured($name = null)
     {
         if ($name !== null) {
+            deprecationWarning(
+                'Checking for a named engine with configured() is deprecated. ' .
+                'Use Configure::isConfigured() instead.'
+            );
+
             return isset(static::$_engines[$name]);
         }
 
@@ -273,6 +281,17 @@ class Configure
     }
 
     /**
+     * Returns true if the Engine objects is configured.
+     *
+     * @param string $name Engine name.
+     * @return bool
+     */
+    public static function isConfigured($name)
+    {
+        return isset(static::$_engines[$name]);
+    }
+
+    /**
      * Remove a configured engine. This will unset the engine
      * and make any future attempts to use it cause an Exception.
      *

+ 23 - 4
tests/TestCase/Core/ConfigureTest.php

@@ -299,8 +299,8 @@ class ConfigureTest extends TestCase
         try {
             Configure::load('non_existing_configuration_file');
         } catch (\Exception $e) {
-            $result = Configure::configured('default');
-            $this->assertTrue($result);
+            $this->assertTrue(Configure::isConfigured('default'));
+            $this->assertFalse(Configure::isConfigured('non_existing_configuration_file'));
         }
     }
 
@@ -485,14 +485,33 @@ class ConfigureTest extends TestCase
 
         $this->assertContains('test', $configured);
 
-        $this->assertTrue(Configure::configured('test'));
-        $this->assertFalse(Configure::configured('fake_garbage'));
+        $this->assertTrue(Configure::isConfigured('test'));
+        $this->assertFalse(Configure::isConfigured('fake_garbage'));
 
         $this->assertTrue(Configure::drop('test'));
         $this->assertFalse(Configure::drop('test'), 'dropping things that do not exist should return false.');
     }
 
     /**
+     * test deprecated behavior of configured
+     *
+     * @deprecated
+     * @return void
+     */
+    public function testConfigured()
+    {
+        $this->deprecated(function () {
+            $engine = new PhpConfig();
+            Configure::config('test', $engine);
+
+            $configured = Configure::configured();
+            $this->assertContains('test', $configured);
+            $this->assertTrue(Configure::configured('test'));
+            $this->assertTrue(Configure::configured('default'));
+        });
+    }
+
+    /**
      * Test that clear wipes all values.
      *
      * @return void