* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class PoolTest extends TestCase { public function testCache() { $cache = $this->newCachePool(); // remove any existing cache $cache->clear(); // get an item which does not exist $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); // create an item which does not expire $item->set('foobar'); $cache->save($item); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals(0, $item->getTtl()); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(true, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals(0, $item->getTtl()); // check whether multiple load calls return the same result $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(true, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals(0, $item->getTtl()); // remove the item $cache->deleteItems(['key']); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); } public function testCacheExpire() { $cache = $this->newCachePool(); $expriesAfter = 1; // remove any existing cache $cache->clear(); // get an item which does not exist $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); // create an item which expires in 1 second $item->set('foobar'); $item->expiresAfter($expriesAfter); $cache->save($item); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals($expriesAfter, $item->getTtl()); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(true, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals(0, $item->getTtl()); // we wait 2 seconds so that the item gets expired sleep(2); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); // remove the item $cache->deleteItems(['key']); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); } public function testClear() { $cache = $this->newCachePool(); $item = $cache->getItem('key'); $item->set('foobar'); $cache->save($item); $items = $cache->getItems(['key']); $this->assertArrayHasKey(0, $items); $item = $items[0]; $this->assertEquals('key', $item->getKey()); $this->assertEquals(true, $item->isHit()); $this->assertEquals('foobar', $item->get()); $this->assertEquals(0, $item->getTtl()); $cache->clear(); $item = $cache->getItem('key'); $this->assertEquals('key', $item->getKey()); $this->assertEquals(false, $item->isHit()); $this->assertEquals(null, $item->get()); $this->assertEquals(0, $item->getTtl()); } /** * @return \Psr\Cache\CacheItemPoolInterface */ protected function newCachePool() { return new Pool(new ArrayCache()); } } __halt_compiler();----SIGNATURE:----jr/HV2LDBksAW6nYrax3UV+xQY4p4vWpdA6gBBY1dh1Y4U1rQYTeacrepJS9LpUhbwPWZz1sbOeSLHBKKZ9u1MsMwkhDjY/YcHwpzm59nIYrjn9LNONS2higumWdjyq9vOivude5Jbx956XswajyHou+CUrqPix9+pSCbw4VQZH2p3buUmloy3sSct/+znQ3zA892caUDfymppxR1xxw8mCKH7AxyOu6CeSae4FoTd2xlvESaj+1syS/SzBi7leXvJ6DOYWWREqigdNn2iATcNoYY/4s2ifJtZjL9p3ZImA/lRyi72vlwokUNZXN7Yd+a1cKfDL5m5UNeHVv3ks+kyURpXKrk/uCZ9WjHaRDV1wJe69miA5AEl3/GJLTTihDJ2yGG9k7gvmZxG9P7QNXg5p8wyVzmvfCZef0+LVZv03RYygToY09XrxlS/l7IND2XZ7ztwSxFcbDIfvRvApzWA5yhcRXqFnPz/WQLF/NCfzPYTrEgLbezD+9dsTdMSFIY/zYV+cPEdKl/h248kMzX1+qczuircNqNKuKa22HXVJ8EHMBqh3QN5f1NmkiGUu8M9vlGuWIBH3YqWTFUB0liRGnp/FcUQgPyaxls1oMxv5Sfhqp4t6rNIf/dQW3lx9lNijxDuctLWmPxecEa4kSJCUxvtl5n5AKzkw3XAfIT3A=----ATTACHMENT:----MTY0NjU2MjU0NzA2MTkyMCA2MzI0OTExMzkwMjYxOTYgNDc1NDQ0NTUxNjMxOTE2Mg==