-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Namespace] Added test to prove correctness. (#160)
* Added test to prove correctness. * cs * Added test for getting items * Use "use" statement * Applied changes from StyleCI * Updated version
- Loading branch information
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of php-cache organization. | ||
* | ||
* (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Cache\Namespaced\Tests; | ||
|
||
use Cache\Adapter\Memcached\MemcachedCachePool; | ||
use Cache\Hierarchy\HierarchicalPoolInterface; | ||
use Cache\Namespaced\NamespacedCachePool; | ||
use Memcached; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
/** | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class IntegrationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @type CacheItemPoolInterface|HierarchicalPoolInterface | ||
*/ | ||
private $cache; | ||
|
||
protected function setUp() | ||
{ | ||
$cache = new Memcached(); | ||
$cache->addServer('localhost', 11211); | ||
|
||
$this->cache = new MemcachedCachePool($cache); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
if ($this->cache !== null) { | ||
$this->cache->clear(); | ||
} | ||
} | ||
|
||
public function testGetItem() | ||
{ | ||
$namespace = 'ns'; | ||
$nsPool = new NamespacedCachePool($this->cache, $namespace); | ||
|
||
$item = $nsPool->getItem('key'); | ||
$this->assertEquals("|$namespace|key", $item->getKey()); | ||
} | ||
|
||
public function testGetItems() | ||
{ | ||
$namespace = 'ns'; | ||
$nsPool = new NamespacedCachePool($this->cache, $namespace); | ||
|
||
$items = $nsPool->getItems(['key0', 'key1']); | ||
|
||
$str = "|$namespace|key0"; | ||
$this->assertTrue(isset($items[$str])); | ||
$this->assertEquals($str, $items[$str]->getKey()); | ||
|
||
$str = "|$namespace|key1"; | ||
$this->assertTrue(isset($items[$str])); | ||
$this->assertEquals($str, $items[$str]->getKey()); | ||
} | ||
|
||
public function testSave() | ||
{ | ||
$namespace = 'ns'; | ||
$nsPool = new NamespacedCachePool($this->cache, $namespace); | ||
|
||
$item = $nsPool->getItem('key'); | ||
$item->set('foo'); | ||
$nsPool->save($item); | ||
|
||
$this->assertTrue($nsPool->hasItem('key')); | ||
$this->assertFalse($this->cache->hasItem('key')); | ||
} | ||
|
||
public function testSaveDeferred() | ||
{ | ||
$namespace = 'ns'; | ||
$nsPool = new NamespacedCachePool($this->cache, $namespace); | ||
|
||
$item = $nsPool->getItem('key'); | ||
$item->set('foo'); | ||
$nsPool->saveDeferred($item); | ||
|
||
$this->assertTrue($nsPool->hasItem('key')); | ||
$this->assertFalse($this->cache->hasItem('key')); | ||
|
||
$nsPool->commit(); | ||
$this->assertTrue($nsPool->hasItem('key')); | ||
$this->assertFalse($this->cache->hasItem('key')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters