Skip to content

Commit

Permalink
Backport isConfigured
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Jul 7, 2018
1 parent 08c667f commit 02ceac0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/Core/Configure.php
Expand Up @@ -260,18 +260,37 @@ public static function config($name, ConfigEngineInterface $engine)
/**
* 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]);
}

return array_keys(static::$_engines);
}

/**
* 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.
Expand Down
27 changes: 23 additions & 4 deletions tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -299,8 +299,8 @@ public function testLoadDefaultConfig()
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'));
}
}

Expand Down Expand Up @@ -485,13 +485,32 @@ public function testEngineSetup()

$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.
*
Expand Down

0 comments on commit 02ceac0

Please sign in to comment.