Skip to content

Commit

Permalink
Merge pull request #29 from kschroeder/develop
Browse files Browse the repository at this point in the history
Testing the cache factory with the Redis and Filesystsem adapters
  • Loading branch information
kschroeder committed Feb 17, 2017
2 parents 62d33e6 + 6c190c5 commit 84df873
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/Manager/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ public function getCache(\SimpleXMLElement $element)
'options' => []
];
if (isset($element->options)) {
foreach ($element->options->children() as $value) {
if ($value instanceof \SimpleXMLElement) {
$config['options'][$value->getName()] = (string)$value;
}
}
$options = json_encode($element->options);
$config['options'] = json_decode($options, true);
}
$cache = StorageFactory::factory($config);
return $cache;
Expand Down
67 changes: 67 additions & 0 deletions tests/Manager/CacheFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Magium\Configuration\Tests\Manager;

use Magium\Configuration\Manager\CacheFactory;
use PHPUnit\Framework\TestCase;
use Zend\Cache\Storage\Adapter\Filesystem;
use Zend\Cache\Storage\Adapter\Redis;

class CacheFactoryTest extends TestCase
{

public function testBasicCacheConfiguration()
{
$simpleXml = simplexml_load_string(
<<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<magium xmlns="http://www.magiumlib.com/BaseConfiguration">
<persistenceConfiguration>
<driver></driver>
<database></database>
</persistenceConfiguration>
<contextConfigurationFile file="asd" type="xml"/>
<cache>
<adapter>filesystem</adapter>
</cache>
</magium>
XML
);

$cacheFactory = new CacheFactory();
$cache = $cacheFactory->getCache($simpleXml->cache);
self::assertInstanceOf(Filesystem::class, $cache);
}
public function testCacheConfigurationWithRecursiveOptions()
{
$redis = extension_loaded('redis');
if (!$redis) {
self::markTestSkipped('Redis extension is not loaded');
}
$simpleXml = simplexml_load_string(
<<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<magium xmlns="http://www.magiumlib.com/BaseConfiguration">
<persistenceConfiguration>
<driver></driver>
<database></database>
</persistenceConfiguration>
<contextConfigurationFile file="asd" type="xml"/>
<cache>
<adapter>redis</adapter>
<options>
<server>localhost:6379</server>
</options>
</cache>
</magium>
XML
);

$cacheFactory = new CacheFactory();
$methods = get_class_methods(new Redis());
$cache = $cacheFactory->getCache($simpleXml->cache);
self::assertInstanceOf(Redis::class, $cache);
}

}

0 comments on commit 84df873

Please sign in to comment.