* @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:----js5rbTq1JninZj8J/kExoXB9bcQzgUWxyz99Y7x3aTe92POq3+0FHbV6Cy0nSSUW2oTlYafOQY6dgVvF7lX65HF6C+ten0qn6KTxBcZP7qIClfeXJ8cSXibOJp3VCu2DdA+YYjYZBVoui2peMkkFteNM2sRJW382g09Y3oDnFgCO1arhyJUyjPg+mWHDBYsSgaN10snIavMkAsYANQs+9n6c6FcCmYlrqA6OGQtsBFgiy1C6zYigsb35iucErrp21Ql7Z4KT+7XAoMV+/AIMBXwTeKVYUhVoR1DOA8c6lmBVoeq+6a61hviht2S0VR4gFNleoNWgv/YxxVqWkE5TLC4xQM3DgxZ60Sz2aiUt3HaN3ZEWKm6/MH9EeLLA6tMQ1nMhrv1+sSMES2IC4tLb5O1TUm4vWwGjI4i9sVQ2QYOpO66GVCVn6PJW0shJmQavv+C4iDKy4Bah0jJ1FQEYKcPfPx8iauybORZPZblNsL/WHhC0yQRYChr7Tp1UeTozjE4XEFOusVFDiU8TnBgfQJyJVm14A3+6v/A3KHTu1cFKLo8fzWgTMafRsPKaqugHd+SURniLgpMvSg+07xlP1o7lCiCjp6w+pk7oY0cpdYJsYXAjAv2Hr6HdGL+QwwXqxm9Hp5Tvk96gr4KuSnfqfqgiCLn8xJCEnGwDeFxhl9Q=----ATTACHMENT:----ODA0NTQxOTUzNDY3MDk1MyA2NTg3MjE4NTM3MzUwNTcyIDM4OTcxMjIyMjYxMzY4NDY=