Skip to content

Commit

Permalink
remove confusing method Cache::settings
Browse files Browse the repository at this point in the history
Having both Cache::config (from the StaticConfigTrait) and
Cache::settings is pretty confusing, however it's also not necessary

instead of

	Cache::settings('foo')

the following can be used:

	Cache::engine('foo')->config();

Renamed all the `$settings` variables in cache tests to `$config` too
  • Loading branch information
AD7six committed Nov 19, 2013
1 parent c7ec4ab commit 02f6ccc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 65 deletions.
16 changes: 0 additions & 16 deletions Cake/Cache/Cache.php
Expand Up @@ -363,22 +363,6 @@ public static function clearGroup($group, $config = 'default') {
return $success;
}

/**
* Return the settings for the named cache engine.
*
* @param string $name Name of the configuration to get settings for. Defaults to 'default'
* @return array list of settings for this engine
* @see Cache::config()
*/
public static function settings($config = 'default') {
$engine = static::engine($config);
if (!$engine) {
return [];
}

return $engine->settings();
}

/**
* Retrieve group names to config mapping.
*
Expand Down
3 changes: 1 addition & 2 deletions Cake/Cache/CacheEngine.php
Expand Up @@ -70,8 +70,7 @@ abstract class CacheEngine {
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($config = []) {
$config += $this->_config + $this->_defaultConfig;
$this->_config = $config;
$this->_config = $config + $this->_defaultConfig;
if (!empty($this->_config['groups'])) {
sort($this->_config['groups']);
$this->_groupPrefix = str_repeat('%s_', count($this->_config['groups']));
Expand Down
4 changes: 2 additions & 2 deletions Cake/Test/TestCase/Cache/Engine/ApcEngineTest.php
Expand Up @@ -60,13 +60,13 @@ public function tearDown() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'Apc',
'prefix' => 'cake_',
];
Cache::drop('apc');
Cache::config('apc', array_merge($defaults, $settings));
Cache::config('apc', array_merge($defaults, $config));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Cake/Test/TestCase/Cache/Engine/FileEngineTest.php
Expand Up @@ -66,13 +66,13 @@ public function tearDown() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'File',
'path' => TMP . 'tests',
];
Cache::drop('file_test');
Cache::config('file_test', array_merge($defaults, $settings));
Cache::config('file_test', array_merge($defaults, $config));
}

/**
Expand Down
50 changes: 25 additions & 25 deletions Cake/Test/TestCase/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -71,14 +71,14 @@ public function setUp() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'Memcached',
'prefix' => 'cake_',
'duration' => 3600
];
Cache::drop('memcached');
Cache::config('memcached', array_merge($defaults, $settings));
Cache::config('memcached', array_merge($defaults, $config));
}

/**
Expand All @@ -98,13 +98,13 @@ public function tearDown() {
}

/**
* testSettings method
* testConfig method
*
* @return void
*/
public function testSettings() {
$settings = Cache::settings('memcached');
unset($settings['path']);
public function testConfig() {
$config = Cache::engine('memcached')->config();
unset($config['path']);
$expecting = array(
'prefix' => 'cake_',
'duration' => 3600,
Expand All @@ -117,7 +117,7 @@ public function testSettings() {
'groups' => array(),
'serialize' => 'php'
);
$this->assertEquals($expecting, $settings);
$this->assertEquals($expecting, $config);
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testCompressionSetting() {
*/
public function testInvalidSerializerSetting() {
$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'className' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
Expand All @@ -162,7 +162,7 @@ public function testInvalidSerializerSetting() {
$this->setExpectedException(
'Cake\Error\Exception', 'invalid_serializer is not a valid serializer engine for Memcached'
);
$Memcached->init($settings);
$Memcached->init($config);
}

/**
Expand All @@ -172,14 +172,14 @@ public function testInvalidSerializerSetting() {
*/
public function testPhpSerializerSetting() {
$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'className' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
'serialize' => 'php'
);

$Memcached->init($settings);
$Memcached->init($config);
$this->assertEquals(Memcached::SERIALIZER_PHP, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER));
}

Expand All @@ -195,14 +195,14 @@ public function testJsonSerializerSetting() {
);

$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'engine' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
'serialize' => 'json'
);

$Memcached->init($settings);
$Memcached->init($config);
$this->assertEquals(Memcached::SERIALIZER_JSON, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER));
}

Expand All @@ -218,14 +218,14 @@ public function testIgbinarySerializerSetting() {
);

$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'engine' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
'serialize' => 'igbinary'
);

$Memcached->init($settings);
$Memcached->init($config);
$this->assertEquals(Memcached::SERIALIZER_IGBINARY, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER));
}

Expand All @@ -241,7 +241,7 @@ public function testJsonSerializerThrowException() {
);

$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'className' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
Expand All @@ -251,7 +251,7 @@ public function testJsonSerializerThrowException() {
$this->setExpectedException(
'Cake\Error\Exception', 'Memcached extension is not compiled with json support'
);
$Memcached->init($settings);
$Memcached->init($config);
}

/**
Expand All @@ -266,7 +266,7 @@ public function testIgbinarySerializerThrowException() {
);

$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'engine' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
Expand All @@ -276,7 +276,7 @@ public function testIgbinarySerializerThrowException() {
$this->setExpectedException(
'Cake\Error\Exception', 'Memcached extension is not compiled with igbinary support'
);
$Memcached->init($settings);
$Memcached->init($config);
}

/**
Expand All @@ -287,7 +287,7 @@ public function testIgbinarySerializerThrowException() {
*/
public function testSaslAuthException() {
$Memcached = new TestMemcachedEngine();
$settings = array(
$config = array(
'engine' => 'Memcached',
'servers' => array('127.0.0.1:11211'),
'persistent' => false,
Expand All @@ -303,11 +303,11 @@ public function testSaslAuthException() {
$this->setExpectedException(
'Cake\Error\Exception', 'Memcached extension is not build with SASL support'
);
$Memcached->init($settings);
$Memcached->init($config);
}

/**
* testSettings method
* testConfig method
*
* @return void
*/
Expand All @@ -330,8 +330,8 @@ public function testMultipleServers() {
$Memcached = new MemcachedEngine();
$Memcached->init(array('engine' => 'Memcached', 'servers' => $servers));

$settings = $Memcached->settings();
$this->assertEquals($settings['servers'], $servers);
$config = $Memcached->config();
$this->assertEquals($config['servers'], $servers);
Cache::drop('dual_server');
}

Expand Down Expand Up @@ -649,7 +649,7 @@ public function testZeroDuration() {
*/
public function testLongDurationEqualToZero() {
$memcached = new TestMemcachedEngine();
$memcached->settings['compress'] = false;
$memcached->_config['compress'] = false;

$mock = $this->getMock('Memcached');
$memcached->setMemcached($mock);
Expand Down
14 changes: 7 additions & 7 deletions Cake/Test/TestCase/Cache/Engine/RedisEngineTest.php
Expand Up @@ -55,23 +55,23 @@ public function tearDown() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'Redis',
'prefix' => 'cake_',
'duration' => 3600
];
Cache::drop('redis');
Cache::config('redis', array_merge($defaults, $settings));
Cache::config('redis', array_merge($defaults, $config));
}

/**
* testSettings method
* testConfig method
*
* @return void
*/
public function testSettings() {
$settings = Cache::settings('redis');
public function testConfig() {
$config = Cache::engine('redis')->config();
$expecting = array(
'prefix' => 'cake_',
'duration' => 3600,
Expand All @@ -84,7 +84,7 @@ public function testSettings() {
'password' => false,
'database' => 0,
);
$this->assertEquals($expecting, $settings);
$this->assertEquals($expecting, $config);
}

/**
Expand All @@ -94,7 +94,7 @@ public function testSettings() {
*/
public function testConnect() {
$Redis = new RedisEngine();
$this->assertTrue($Redis->init(Cache::settings('redis')));
$this->assertTrue($Redis->init(Cache::engine('redis')->config()));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Cake/Test/TestCase/Cache/Engine/WincacheEngineTest.php
Expand Up @@ -56,13 +56,13 @@ public function tearDown() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'Wincache',
'prefix' => 'cake_'
];
Cache::drop('wincache');
Cache::config('wincache', array_merge($defaults, $settings));
Cache::config('wincache', array_merge($defaults, $config));
}

/**
Expand Down
18 changes: 9 additions & 9 deletions Cake/Test/TestCase/Cache/Engine/XcacheEngineTest.php
Expand Up @@ -47,13 +47,13 @@ public function setUp() {
*
* @return void
*/
protected function _configCache($settings = []) {
protected function _configCache($config = []) {
$defaults = [
'className' => 'Xcache',
'prefix' => 'cake_',
];
Cache::drop('xcache');
Cache::config('xcache', array_merge($defaults, $settings));
Cache::config('xcache', array_merge($defaults, $config));
}

/**
Expand All @@ -68,22 +68,22 @@ public function tearDown() {
}

/**
* testSettings method
* testConfig method
*
* @return void
*/
public function testSettings() {
$settings = Cache::settings();
public function testConfig() {
$config = Cache::engine('xcache')->config();
$expecting = [
'prefix' => 'cake_',
'duration' => 3600,
'probability' => 100,
];
$this->assertTrue(isset($settings['PHP_AUTH_USER']));
$this->assertTrue(isset($settings['PHP_AUTH_PW']));
$this->assertTrue(isset($config['PHP_AUTH_USER']));
$this->assertTrue(isset($config['PHP_AUTH_PW']));

unset($settings['PHP_AUTH_USER'], $settings['PHP_AUTH_PW']);
$this->assertEquals($settings, $expecting);
unset($config['PHP_AUTH_USER'], $config['PHP_AUTH_PW']);
$this->assertEquals($config, $expecting);
}

/**
Expand Down

0 comments on commit 02f6ccc

Please sign in to comment.