/**
  * Test if the `valid` method returns true if a resource exists.
  */
 public function testValidReturnsTrue()
 {
     $container = new TempResourceContainer(TempFileResource::TYPE);
     $container->create('php://temp/test', 'test');
     $container->rewind();
     $this->assertTrue($container->valid());
 }
示例#2
0
 /**
  * Test if the `clean` method removes all expired resources.
  */
 public function testCleanRemovesExpiredResources()
 {
     $container = new TempResourceContainer(TempFileResource::TYPE);
     $container->create('php://temp/test1', 'A string')->getStat()->setModificationTime(time() - 5);
     $container->create('php://temp/test2', 'A string')->getStat()->setModificationTime(time() - 5);
     $container->create('php://temp/test3', 'A string')->getStat()->setModificationTime(time() - 5);
     $container->create('php://temp/test4', 'A string');
     $container->create('php://temp/test5', 'A string');
     $adapter = new ResourceAdapter($container);
     $adapter->setLifetime(1);
     $adapter->clean();
     $cnt = 0;
     $container->rewind();
     while ($container->valid()) {
         $container->next();
         $cnt++;
     }
     $this->assertSame(2, $cnt);
 }