Skip to content

Commit

Permalink
Added setOption()
Browse files Browse the repository at this point in the history
  • Loading branch information
frqnck committed Oct 4, 2014
1 parent 9f1c88e commit 26cae39
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,24 @@ public function setOptions(array $options=null)
*/
public function getOption($key)
{
if (isset($this->options[$key])) {
return $this->options[$key];
if (!isset($this->options[$key])) {
throw new PsrCache\InvalidArgumentException(
sprintf('Invalid option "%s"', $key)
);
}

return $this->options[$key];
}

/**
* Sets the named option.
*
* @param string $key
* @param mixed $value
*/
public function setOption($key, $value)
{
return $this->options[$key] = $value;
}

/**
Expand Down
56 changes: 56 additions & 0 deletions tests/AbstractCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
*
* This file is part of the Apix Project.
*
* (c) Franck Cassedanne <franck at ouarz.net>
*
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
*
*/

namespace Apix\Cache\tests;

use Apix\Cache;

class AbstractCacheTest extends TestCase
{
protected $cache = null;

public function setUp()
{
$this->cache = new Cache\Runtime(null, $this->options);
}

public function tearDown()
{
if (null !== $this->cache) {
$this->cache->flush();
unset($this->cache);
}
}

public function testGetOption()
{
$this->assertSame(
$this->options['prefix_key'],
$this->cache->getOption('prefix_key')
);
}

/**
* @expectedException Apix\Cache\PsrCache\InvalidArgumentException
*/
public function testGetOptionThrowAnInvalidArgumentException()
{
$this->cache->getOption('key');
}

public function testSetOption()
{
$this->cache->setOption('prefix_key', 'foo');

$this->assertSame('foo', $this->cache->getOption('prefix_key'));
}
}

0 comments on commit 26cae39

Please sign in to comment.