Beispiel #1
0
 public function testGetCollection()
 {
     $cache = new Cache(new Cache\Handler\Memory());
     $routing = new RoutingFile('tests/PSX/Loader/routes');
     $routingParser = new CachedParser($routing, $cache);
     // we remove previous cache
     $cache->deleteItems([CachedParser::CACHE_KEY]);
     // get collection from the parser
     $collection = $routingParser->getCollection();
     $this->assertInstanceOf('PSX\\Loader\\RoutingCollection', $collection);
     $this->assertEquals(14, count($collection));
     // get collection from the cache
     $collection = $routingParser->getCollection();
     $this->assertInstanceOf('PSX\\Loader\\RoutingCollection', $routingParser->getCollection());
     $this->assertEquals(14, count($collection));
 }
Beispiel #2
0
 public function testCacheExpire()
 {
     $cache = new Cache($this->getHandler());
     // remove any existing cache
     $cache->clear();
     // get an item which does not exist
     $item = $cache->getItem('key');
     $this->assertEquals('key', $item->getKey());
     $this->assertInstanceOf('DateTime', $item->getExpiration());
     $this->assertEquals(false, $item->isHit());
     $this->assertEquals(false, $item->exists());
     $this->assertEquals(null, $item->get());
     // create an item which expires in 2 seconds
     $item->set('foobar', 2);
     $cache->save($item);
     $this->assertEquals('key', $item->getKey());
     $this->assertInstanceOf('DateTime', $item->getExpiration());
     $this->assertEquals(false, $item->isHit());
     $this->assertEquals(true, $item->exists());
     $this->assertEquals('foobar', $item->get());
     $item = $cache->getItem('key');
     $this->assertEquals('key', $item->getKey());
     $this->assertInstanceOf('DateTime', $item->getExpiration());
     $this->assertEquals(true, $item->isHit());
     $this->assertEquals(true, $item->exists());
     $this->assertEquals('foobar', $item->get());
     // we wait 4 seconds so that the item gets expired
     sleep(4);
     $item = $cache->getItem('key');
     $this->assertEquals('key', $item->getKey());
     $this->assertInstanceOf('DateTime', $item->getExpiration());
     $this->assertEquals(false, $item->isHit());
     $this->assertEquals(false, $item->exists());
     $this->assertEquals(null, $item->get());
     // remove the item
     $cache->deleteItems(['key']);
     $item = $cache->getItem('key');
     $this->assertEquals('key', $item->getKey());
     $this->assertInstanceOf('DateTime', $item->getExpiration());
     $this->assertEquals(false, $item->isHit());
     $this->assertEquals(false, $item->exists());
     $this->assertEquals(null, $item->get());
 }