Exemplo n.º 1
0
 /**
  * test expiration of namespaces and namespace variables by seconds
  * expect expiration of specified keys/namespace
  */
 public function testSetExpirationSeconds()
 {
     $s = new Zend_Session('expireAll');
     $s->a = 'apple';
     $s->p = 'pear';
     $s->o = 'orange';
     $s->setExpirationSeconds(5);
     $core = Zend_Session_Core::getInstance();
     $core->regenerateId();
     $id = Zend_Session_Core::getId();
     session_write_close();
     // release session so process below can use it
     sleep(4);
     // not long enough for things to expire
     exec($this->script . "expireAll {$id} expireAll", $result);
     $result = $this->sortResult($result);
     $expect = ';a === apple;o === orange;p === pear';
     $this->assertTrue($result === $expect, "iteration over default Zend_Session namespace failed; expecting result === '{$expect}', but got '{$result}'");
     sleep(2);
     // long enough for things to expire (total of 6 seconds waiting, but expires in 5)
     exec($this->script . "expireAll {$id} expireAll", $result);
     $result = array_pop($result);
     $this->assertTrue($result === '', "iteration over default Zend_Session namespace failed; expecting result === '', but got '{$result}')");
     session_start();
     // resume artificially suspended session
     // We could split this into a separate test, but actually, if anything leftover from above
     // contaminates the tests below, that is also a bug that we want to know about.
     $s = new Zend_Session('expireGuava');
     $s->setExpirationSeconds(5, 'g');
     // now try to expire only 1 of the keys in the namespace
     $s->g = 'guava';
     $s->p = 'peach';
     $s->p = 'plum';
     session_write_close();
     // release session so process below can use it
     sleep(6);
     // not long enough for things to expire
     exec($this->script . "expireAll {$id} expireGuava", $result);
     $result = $this->sortResult($result);
     session_start();
     // resume artificially suspended session
     $this->assertTrue($result === ';p === plum', "iteration over named Zend_Session namespace failed (result={$result})");
 }