Skip to content

Commit

Permalink
Construct engines before getting groups.
Browse files Browse the repository at this point in the history
Without this groupConfigs() will only return groups from engines that
have been constructed. This makes groupConfigs() non-deterministic and
awkward to use.

Refs #5894
  • Loading branch information
markstory committed Feb 15, 2015
1 parent 961d496 commit 394ade2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Cache/Cache.php
Expand Up @@ -423,14 +423,18 @@ public static function clearGroup($group, $config = 'default')
* $configs = Cache::groupConfigs('posts');
* ```
*
* $config will equal to `['posts' => ['daily', 'weekly']]`
* $configs will equal to `['posts' => ['daily', 'weekly']]`
* Calling this method will load all the configured engines.
*
* @param string|null $group group name or null to retrieve all group mappings
* @return array map of group and all configuration that has the same group
* @throws \InvalidArgumentException
*/
public static function groupConfigs($group = null)
{
foreach (array_keys(static::$_config) as $config) {
static::engine($config);
}
if ($group === null) {
return static::$_groups;
}
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase/Cache/CacheTest.php
Expand Up @@ -255,6 +255,7 @@ public function testConfigRead()
*/
public function testGroupConfigs()
{
Cache::drop('test');
Cache::config('latest', [
'duration' => 300,
'engine' => 'File',
Expand All @@ -265,7 +266,6 @@ public function testGroupConfigs()
'posts' => ['latest'],
'comments' => ['latest'],
];
$engine = Cache::engine('latest');
$result = Cache::groupConfigs();
$this->assertEquals($expected, $result);

Expand All @@ -278,7 +278,6 @@ public function testGroupConfigs()
'groups' => ['posts', 'archive'],
]);

$engine = Cache::engine('page');
$result = Cache::groupConfigs();
$expected = [
'posts' => ['latest', 'page'],
Expand All @@ -296,7 +295,6 @@ public function testGroupConfigs()
'groups' => ['posts', 'archive', 'comments'],
]);

$engine = Cache::engine('archive');
$result = Cache::groupConfigs('archive');
$this->assertEquals(['archive' => ['archive', 'page']], $result);
}
Expand Down

0 comments on commit 394ade2

Please sign in to comment.