コード例 #1
0
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testSessionTimeoutControlKey()
 {
     $middleware = new SessionWare(['name' => 'SessionWareSession', 'timeoutKey' => '__TIMEOUT__']);
     $middleware($this->request, $this->response, $this->callback);
     $limitTimeout = time() - SessionWare::SESSION_LIFETIME_EXTENDED;
     $_SESSION['__TIMEOUT__'] = $limitTimeout;
     session_write_close();
     $sessionHolder = new \stdClass();
     $middleware->addListener('pre.session_timeout', function ($sessionId) use($sessionHolder) {
         $sessionHolder->id = $sessionId;
     });
     $assert = $this;
     $middleware->addListener('post.session_timeout', function ($sessionId) use($assert, $sessionHolder) {
         $assert::assertNotNull($sessionHolder->id);
         $assert::assertNotEquals($sessionHolder->id, $sessionId);
     });
     $middleware($this->request, $this->response, $this->callback);
     self::assertEquals(PHP_SESSION_ACTIVE, session_status());
     self::assertTrue(array_key_exists('__TIMEOUT__', $_SESSION));
     self::assertNotEquals($_SESSION['__TIMEOUT__'], $limitTimeout);
 }