diff --git a/src/Container.php b/src/Container.php index 7e6281df..a603664e 100644 --- a/src/Container.php +++ b/src/Container.php @@ -470,6 +470,7 @@ public function setExpirationSeconds($ttl, $vars = null) } if (null === $vars) { + $this->expireKeys(); // first we need to expire global key, since it can already be expired $data = array('EXPIRE' => $ts); } elseif (is_array($vars)) { // Cannot pass "$this" to a lambda @@ -518,6 +519,7 @@ public function setExpirationHops($hops, $vars = null) } if (null === $vars) { + $this->expireKeys(); // first we need to expire global key, since it can already be expired $data = array('EXPIRE_HOPS' => array('hops' => $hops, 'ts' => $ts)); } elseif (is_array($vars)) { // Cannot pass "$this" to a lambda diff --git a/test/ContainerTest.php b/test/ContainerTest.php index 045fd06c..3dfaa22d 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -23,6 +23,16 @@ */ class ContainerTest extends \PHPUnit_Framework_TestCase { + /** + * @var Manager + */ + protected $manager; + + /** + * @var Container + */ + protected $container; + public function setUp() { $this->forceAutoloader(); @@ -283,6 +293,15 @@ public function testKeyExistsWithExpirationInPastReturnsFalse() $this->assertTrue(isset($this->container->bar)); } + public function testKeyExistsWithContainerExpirationInPastWithSetExpirationSecondsReturnsFalse() + { + $this->container->foo = 'bar'; + $storage = $this->manager->getStorage(); + $storage->setMetadata('Default', array('EXPIRE' => $_SERVER['REQUEST_TIME'] - 18600)); + $this->container->setExpirationSeconds(1); + $this->assertFalse(isset($this->container->foo)); + } + public function testSettingExpiredKeyOverwritesExpiryMetadataForThatKey() { $this->container->foo = 'bar';