From 93b4809bc82ffb2aa83717f4b24531eeb3e9fe7c Mon Sep 17 00:00:00 2001
From: Alorel * @param LoggerInterface $logger A logger object. If omitted, AloFramework\Log will be used. */
- function __construct(Config $cfg = null, LoggerInterface $logger = null) {
- $this->config = Alo::ifnull($cfg, new Config());
- $this->log = Alo::ifnull($logger, new Log());
- $this->setID();
+ }
+ $this->config = Alo::ifnull($cfg, new Config());
+ $this->log = Alo::ifnull($logger, new Log());
+ $this->setID(); } /**
@@ -661,22 +661,22 @@
* Sets the session ID variable & the cookie * @return string The generated ID */
- protected function setID() {
+ $c = Alo::nullget($_COOKIE[$this->config->cookie]); $c = Alo::nullget($_COOKIE[$this->config->cookie]); //@codeCoverageIgnoreStart if ($c && strlen($c) == strlen(hash($this->config->sessionAlgo, 1))) { $sid = $c; } else {
- //@codeCoverageIgnoreEnd
- do {
- $sid = Alo::getUniqid($this->config->sessionAlgo, 'session' . Alo::getFingerprint('md5'));
+ } while ($this->idExists($sid));
+ do {
+ $sid = Alo::getUniqid($this->config->sessionAlgo, 'session' . Alo::getFingerprint('md5')); } while ($this->idExists($sid)); }
-
+ session_id($sid); session_id($sid);
-
+ $this->log->debug('Session ID set to ' . $sid); $this->log->debug('Session ID set to ' . $sid);
-
+ return $sid; return $sid; }
@@ -696,14 +696,14 @@
/** * @return bool */
- static function destroySafely() {
- if (self::isActive()) {
+ session_destroy();
+ if (self::isActive()) { session_destroy();
-
+ return true; return true;
- } else {
+ return false; return false;
- }
+ } } /**
@@ -712,7 +712,7 @@
* Returns the last started session object. This is reset back to null after the session is destroyed or closed. * @since 1.2 */
- static function getLastActiveSession() {
+ return self::$activeSession; return self::$activeSession; }
@@ -723,7 +723,7 @@
/** * @since 1.2.1 */
- function jsonSerialize() {
+ return self::isActive() ? $_SESSION : []; return self::isActive() ? $_SESSION : []; }
@@ -732,7 +732,7 @@
/** * @return bool */
- static function isActive() {
+ return session_status() === PHP_SESSION_ACTIVE; return session_status() === PHP_SESSION_ACTIVE; }
@@ -741,27 +741,27 @@
/** * @return self */
- function start() {
- $this->log->debug('Starting session with ' . __CLASS__);
+ if (self::isActive()) {
+ $this->log->debug('Starting session with ' . __CLASS__); if (self::isActive()) { //Can't test this via PHPUnit //@codeCoverageIgnoreStart session_write_close();
- //@codeCoverageIgnoreEnd
- trigger_error('A session has already been started - it has now been destroyed to start the new one',
+ E_USER_WARNING);
+ trigger_error('A session has already been started - it has now been destroyed to start the new one', E_USER_WARNING); //@codeCoverageIgnoreStart } //@codeCoverageIgnoreEnd
-
- self::$activeSession = &$this;
- session_set_cookie_params($this->config->timeout, '/', null, $this->config->secure, true);
+ session_name($this->config->cookie);
+ self::$activeSession = &$this;
+ session_set_cookie_params($this->config->timeout, '/', null, $this->config->secure, true); session_name($this->config->cookie);
-
- session_set_save_handler($this, false);
- session_start();
+ $this->identityCheck();
+ session_set_save_handler($this, false);
+ session_start(); $this->identityCheck();
-
+ return $this; return $this; }
@@ -771,20 +771,20 @@
/** * @return boolean TRUE if the check has passed, FALSE if not and the session has been terminated. */
- private function identityCheck() {
+ $fingerprint = self::getFingerprint(); $fingerprint = self::getFingerprint();
-
- if (!Alo::nullget($_SESSION[$this->config->fingerprint])) {
- $_SESSION[$this->config->fingerprint] = $fingerprint;
+ } elseif ($fingerprint !== $_SESSION[$this->config->fingerprint]) {
+ if (!Alo::nullget($_SESSION[$this->config->fingerprint])) {
+ $_SESSION[$this->config->fingerprint] = $fingerprint; } elseif ($fingerprint !== $_SESSION[$this->config->fingerprint]) { //@codeCoverageIgnoreStart $this->handleIdentityCheckFailure(session_id()); return false; //@codeCoverageIgnoreEnd
- }
+ $this->log->debug('Identity check passed for session ID ' . session_id()); $this->log->debug('Identity check passed for session ID ' . session_id());
-
+ return true; return true; }
@@ -794,7 +794,7 @@
/** * @return string */
- private static function getFingerprint() {
+ return md5('AloSession' . Alo::getFingerprint('md5')); return md5('AloSession' . Alo::getFingerprint('md5')); }
@@ -804,9 +804,9 @@
/** * @param string $sessionID The session ID that failed */
- protected function handleIdentityCheckFailure($sessionID) {
- $this->log->notice('Session identity check failed for session ID ' . $sessionID);
- session_destroy();
+ }
+ $this->log->notice('Session identity check failed for session ID ' . $sessionID);
+ session_destroy(); } /**
@@ -833,10 +833,10 @@
* Close the session * internally to PHP for processing. */
- function destroy($sessionID) {
- $this->log->info('Destroyed session ' . $sessionID);
+ self::$activeSession = null;
+ $this->log->info('Destroyed session ' . $sessionID); self::$activeSession = null;
-
+ return setcookie($this->config->cookie, '', time() - 3, null, null, $this->config->secure, true); return setcookie($this->config->cookie, '', time() - 3, null, null, $this->config->secure, true); }
@@ -880,15 +880,15 @@
/** * @return boolean */
- function offsetExists($offset) {
- if (!self::isActive()) {
+ self::sessionRequiredWarning(__METHOD__);
+ if (!self::isActive()) { self::sessionRequiredWarning(__METHOD__); //@codeCoverageIgnoreStart return false; //@codeCoverageIgnoreEnd }
-
+ return isset($_SESSION[$offset]); return isset($_SESSION[$offset]); }
@@ -898,7 +898,7 @@
/** * @param string $method The method used */
- private static function sessionRequiredWarning($method) {
+ trigger_error($method . ' failed: the session must be started first', E_USER_WARNING); trigger_error($method . ' failed: the session must be started first', E_USER_WARNING); //@codeCoverageIgnoreStart }
@@ -913,7 +913,7 @@
//@codeCoverageIgnoreEnd * @uses AbstractSession::offsetGet() */
- function __get($key) {
+ return $this->offsetGet($key); return $this->offsetGet($key); }
@@ -926,8 +926,8 @@
/** * @uses AbstractSession::offsetSet() */
- function __set($key, $value) {
- $this->offsetSet($key, $value);
+ }
+ $this->offsetSet($key, $value); } /**
@@ -939,15 +939,15 @@
* Offset to retrieve * @return mixed */
- function offsetGet($offset) {
- if (!self::isActive()) {
+ self::sessionRequiredWarning(__METHOD__);
+ if (!self::isActive()) { self::sessionRequiredWarning(__METHOD__); //@codeCoverageIgnoreStart return null; //@codeCoverageIgnoreEnd }
-
+ return Alo::get($_SESSION[$offset]); return Alo::get($_SESSION[$offset]); }
@@ -961,14 +961,14 @@
/** * @return void */
- function offsetSet($offset, $value) {
- if (!self::isActive()) {
+ self::sessionRequiredWarning(__METHOD__);
+ if (!self::isActive()) { self::sessionRequiredWarning(__METHOD__); //@codeCoverageIgnoreStart } else {
- //@codeCoverageIgnoreEnd
+ $_SESSION[$offset] = $value; $_SESSION[$offset] = $value;
- }
+ } } /**
@@ -980,24 +980,24 @@
* Offset to unset * @return void */
- function offsetUnset($offset) {
- if (!self::isActive()) {
+ self::sessionRequiredWarning(__METHOD__);
+ if (!self::isActive()) { self::sessionRequiredWarning(__METHOD__); //@codeCoverageIgnoreStart } else {
- //@codeCoverageIgnoreEnd
+ unset($_SESSION[$offset]); unset($_SESSION[$offset]);
- }
+ } } /** * Saves session data * @author Art <a.molcanovas@gmail.com> */
- function __destruct() {
- if (self::isActive()) {
- session_write_close();
- }
+ }
+ if (self::isActive()) {
+ session_write_close();
+ } } /**
@@ -1006,9 +1006,9 @@
* Checks if the session should be saved/written * @since 1.1 */
- protected function shouldBeSaved() {
+ $isCli = Alo::isCliRequest(); $isCli = Alo::isCliRequest();
-
+ return !$isCli || ($isCli && $this->config->saveCLI); return !$isCli || ($isCli && $this->config->saveCLI); }
@@ -1023,7 +1023,7 @@ } Legend
Dead Code
- Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/Config.php.html b/coverage/Config.php.html index 44b67d5..f71c816 100644 --- a/coverage/Config.php.html +++ b/coverage/Config.php.html @@ -261,8 +261,8 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/MySQLNoEventSession.php.html b/coverage/MySQLNoEventSession.php.html index 534533d..bcc9e7c 100644 --- a/coverage/MySQLNoEventSession.php.html +++ b/coverage/MySQLNoEventSession.php.html @@ -201,7 +201,7 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/MySQLSession.php.html b/coverage/MySQLSession.php.html index 87b0f64..3eb1ff6 100644 --- a/coverage/MySQLSession.php.html +++ b/coverage/MySQLSession.php.html @@ -402,8 +402,8 @@ class="default"> null) {Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/RedisSession.php.html b/coverage/RedisSession.php.html index 42ded66..2ab8dda 100644 --- a/coverage/RedisSession.php.html +++ b/coverage/RedisSession.php.html @@ -493,8 +493,8 @@ class="comment">//@codeCoverageIgnoreEndGenerated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/SessionException.php.html b/coverage/SessionException.php.html index 7d293cb..31ca01c 100644 --- a/coverage/SessionException.php.html +++ b/coverage/SessionException.php.html @@ -145,7 +145,7 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/Token.php.html b/coverage/Token.php.html index 2e85215..ed50f7f 100644 --- a/coverage/Token.php.html +++ b/coverage/Token.php.html @@ -1916,7 +1916,7 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/dashboard.html b/coverage/dashboard.html index 8509101..36d89a6 100644 --- a/coverage/dashboard.html +++ b/coverage/dashboard.html @@ -138,7 +138,7 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/coverage/index.html b/coverage/index.html index 1f25bad..94142c3 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -294,7 +294,7 @@Generated by PHP_CodeCoverage 3.1.1 using PHP 5.6.18 and PHPUnit - 5.2.3 at Mon Feb 8 19:54:38 GMT 2016. + 5.2.3 at Mon Feb 8 20:12:41 GMT 2016.
diff --git a/tests/AbstractSessionTest.php b/tests/AbstractSessionTest.php index dc217da..b41f5a9 100644 --- a/tests/AbstractSessionTest.php +++ b/tests/AbstractSessionTest.php @@ -2,12 +2,18 @@ namespace AloFramework\Session\Tests; -use AloFramework\Session\Config; +use AloFramework\Common\Alo; use AloFramework\Session\Config as Cfg; use AloFramework\Session\RedisSession as Sess; use PHPUnit_Framework_TestCase; use Redis; +if (file_exists('vendor/autoload.php')) { + require_once 'vendor/autoload.php'; +} else { + require_once '../vendor/autoload.php'; +} + class AbstractSessionTest extends PHPUnit_Framework_TestCase { /** @var Cfg */ @@ -60,7 +66,7 @@ function testDestruct() { $this->assertEquals('s:3:"foo"', self::sessionUnserialize($this->redis->get($key))[__METHOD__]); } - protected static function sessionUnserialize($str) { + public static function sessionUnserialize($str) { $spl = explode(';', $str); foreach ($spl as $k => $s) { @@ -76,18 +82,19 @@ protected static function sessionUnserialize($str) { function testJsonSerializeNoSession() { $sess = new Sess($this->redis, $this->cfg); - $this->assertEquals(json_encode([]), json_encode($sess)); + $enc = json_encode($sess); + $this->assertEquals(json_encode([]), $enc); } function testJsonSerializeSession() { $sess = new Sess($this->redis, $this->cfg); $sess->start(); - $finger = (new Config())->get(Config::CFG_FINGERPRINT_NAME); + $finger = (new Cfg())->get(Cfg::CFG_FINGERPRINT_NAME); $_SESSION[__METHOD__] = 'bar'; - $pattern = '~{"' . $finger . '":"[a-z0-9]{32}","' . __METHOD__ . '":"bar"}~i'; - $str = json_encode($sess); + $code = json_decode(json_encode($sess), true); - $this->assertEquals(1, preg_match($pattern, $str)); + $this->assertEquals('bar', Alo::get($code[__METHOD__])); + $this->assertTrue(isset($code[$finger])); } function testDestroySafely() { diff --git a/tests/MySQLNoEventTest.php b/tests/MySQLNoEventTest.php index 0c7a37b..200fb4b 100644 --- a/tests/MySQLNoEventTest.php +++ b/tests/MySQLNoEventTest.php @@ -1,41 +1,53 @@ assertFalse(Sess::isActive()); - (new Sess($this->client, $this->cfg))->start(); - - $this->assertEquals(1, ini_get('session.gc_probability')); - $this->assertEquals((int)$this->cfg->gc, ini_get('session.gc_divisor')); - $this->assertEquals((int)$this->cfg->timeout, ini_get('session.gc_maxlifetime')); - } - - function testGc() { - $gc = 1; - $cfg = new Cfg([Cfg::CFG_SECURE => false, - Cfg::CFG_TIMEOUT => $gc, - Cfg::CFG_SAVE_CLI => true, - Cfg::CFG_GC => $gc]); - - $sess = (new Sess($this->client, $cfg))->start(); - $id = session_id(); - $_SESSION[__METHOD__] = 'foo'; - session_write_close(); - - $this->assertNotEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . - $id . '\'')->fetchAll(PDO::FETCH_ASSOC)); - sleep(2); - $sess->gc($gc); - $this->assertEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . - $id . '\'')->fetchAll(PDO::FETCH_ASSOC)); - } +namespace AloFramework\Session\Tests; + +use AloFramework\Session\Config as Cfg; +use AloFramework\Session\MySQLNoEventSession as Sess; +use PDO; +use PHPUnit_Framework_TestCase; + +require_once 'MySQLTest.php'; + +class MySQLNoEventTest extends PHPUnit_Framework_TestCase { + /** @var Cfg */ + protected $cfg; + /** @var PDO */ + protected $client; + + function __construct($name = null, array $data = [], $dataName = '') { + parent::__construct($name, $data, $dataName); + $this->cfg = new Cfg([Cfg::CFG_SECURE => false, + Cfg::CFG_SAVE_CLI => true]); + $this->client = MySQLTest::initPDO(); } + + function testStart() { + $this->assertFalse(Sess::isActive()); + (new Sess($this->client, $this->cfg))->start(); + + $this->assertEquals(1, ini_get('session.gc_probability')); + $this->assertEquals((int)$this->cfg->gc, ini_get('session.gc_divisor')); + $this->assertEquals((int)$this->cfg->timeout, ini_get('session.gc_maxlifetime')); + } + + function testGc() { + $gc = 1; + $cfg = new Cfg([Cfg::CFG_SECURE => false, + Cfg::CFG_TIMEOUT => $gc, + Cfg::CFG_SAVE_CLI => true, + Cfg::CFG_GC => $gc]); + + $sess = (new Sess($this->client, $cfg))->start(); + $id = session_id(); + $_SESSION[__METHOD__] = 'foo'; + session_write_close(); + + $this->assertNotEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . + $id . '\'')->fetchAll(PDO::FETCH_ASSOC)); + sleep(2); + $sess->gc($gc); + $this->assertEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . + $id . '\'')->fetchAll(PDO::FETCH_ASSOC)); + } +} diff --git a/tests/MySQLTest.php b/tests/MySQLTest.php index 1135893..d088aa3 100644 --- a/tests/MySQLTest.php +++ b/tests/MySQLTest.php @@ -1,24 +1,35 @@ client = new PDO('mysql:dbname=phpunit;host=localhost;charset=utf8mb4;port=3306', 'root', ''); - $this->client->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->client->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); - $this->client->query('CREATE TABLE IF NOT EXISTS `alo_session` ( + function __construct($name = null, array $data = [], $dataName = '') { + parent::__construct($name, $data, $dataName); + $this->cfg = new Cfg([Cfg::CFG_SECURE => false, + Cfg::CFG_SAVE_CLI => true]); + + $this->client = self::initPDO(); + } + + public static function initPDO() { + $pdo = new PDO('mysql:dbname=phpunit;host=localhost;charset=utf8mb4;port=3306', 'root', ''); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $pdo->query('CREATE TABLE IF NOT EXISTS `alo_session` ( `id` CHAR(128) CHARACTER SET ascii NOT NULL, `data` TEXT NOT NULL, @@ -28,50 +39,51 @@ function __construct($name = null, array $data = [], $dataName = '') { ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;')->execute(); - } + return $pdo; + } - function testRW() { - $this->assertFalse(Sess::isActive()); + function testRW() { + $this->assertFalse(Sess::isActive()); - (new Sess($this->client, $this->cfg))->start(); - $this->assertTrue(Sess::isActive()); - $prefix = session_id(); - $_SESSION[__METHOD__] = 'foo'; - session_write_close(); - $this->assertFalse(Sess::isActive()); + (new Sess($this->client, $this->cfg))->start(); + $this->assertTrue(Sess::isActive()); + $prefix = session_id(); + $_SESSION[__METHOD__] = 'foo'; + session_write_close(); + $this->assertFalse(Sess::isActive()); - $this->assertEquals($_SESSION[__METHOD__], 'foo'); - $select = - $this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . $prefix . '\'') - ->fetchAll(PDO::FETCH_ASSOC); + $this->assertEquals($_SESSION[__METHOD__], 'foo'); + $select = + $this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . $prefix . '\'') + ->fetchAll(PDO::FETCH_ASSOC); - $this->assertNotEmpty($select); + $this->assertNotEmpty($select); - $sess = self::sessionUnserialize($select[0]['data']); + $sess = AbstractSessionTest::sessionUnserialize($select[0]['data']); - $this->assertTrue(array_key_exists($this->cfg->fingerprint, $sess)); - $this->assertEquals('s:3:"foo"', $sess[__METHOD__]); - } + $this->assertTrue(array_key_exists($this->cfg->fingerprint, $sess)); + $this->assertEquals('s:3:"foo"', $sess[__METHOD__]); + } - function testDestroy() { - $this->assertFalse(Sess::isActive()); + function testDestroy() { + $this->assertFalse(Sess::isActive()); - $session = new Sess($this->client, $this->cfg); - $session->start(); - $this->assertTrue(Sess::isActive()); + $session = new Sess($this->client, $this->cfg); + $session->start(); + $this->assertTrue(Sess::isActive()); - $_SESSION[__METHOD__] = 1; - $session->write(session_id(), serialize($_SESSION)); + $_SESSION[__METHOD__] = 1; + $session->write(session_id(), serialize($_SESSION)); - $prefix = session_id(); + $prefix = session_id(); - $this->assertNotEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . - $prefix . '\'')->fetchAll(PDO::FETCH_ASSOC)); + $this->assertNotEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . + $prefix . '\'')->fetchAll(PDO::FETCH_ASSOC)); - session_destroy(); - $this->assertEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . - $prefix . '\'')->fetchAll(PDO::FETCH_ASSOC)); + session_destroy(); + $this->assertEmpty($this->client->query('SELECT `data` FROM `' . $this->cfg->table . '` WHERE `id`=\'' . + $prefix . '\'')->fetchAll(PDO::FETCH_ASSOC)); - $this->assertFalse(Sess::isActive()); - } + $this->assertFalse(Sess::isActive()); } +} diff --git a/tests/RedisTest.php b/tests/RedisTest.php index db011a5..491aab0 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -1,58 +1,64 @@ client = new \Redis(); - $this->client->connect('127.0.0.1'); - } + $this->client = new \Redis(); + $this->client->connect('127.0.0.1'); + $this->cfg = new Cfg([Cfg::CFG_SECURE => false, + Cfg::CFG_SAVE_CLI => true]); + } - function testRW() { - $this->assertFalse(Sess::isActive()); + function testRW() { + $this->assertFalse(Sess::isActive()); - (new Sess($this->client, $this->cfg))->start(); - $this->assertTrue(Sess::isActive()); - $prefix = $this->cfg->prefix . session_id(); - $_SESSION[__METHOD__] = 'foo'; - session_write_close(); - $this->assertFalse(Sess::isActive()); + (new Sess($this->client, $this->cfg))->start(); + $this->assertTrue(Sess::isActive()); + $prefix = $this->cfg->prefix . session_id(); + $_SESSION[__METHOD__] = 'foo'; + session_write_close(); + $this->assertFalse(Sess::isActive()); - $this->assertEquals($_SESSION[__METHOD__], 'foo'); - $this->assertTrue($this->client->exists($prefix)); + $this->assertEquals($_SESSION[__METHOD__], 'foo'); + $this->assertTrue($this->client->exists($prefix)); - $sess = self::sessionUnserialize($this->client->get($prefix)); + $sess = AbstractSessionTest::sessionUnserialize($this->client->get($prefix)); - $this->assertTrue(array_key_exists($this->cfg->fingerprint, $sess)); - $this->assertEquals('s:3:"foo"', $sess[__METHOD__]); - } + $this->assertTrue(array_key_exists($this->cfg->fingerprint, $sess)); + $this->assertEquals('s:3:"foo"', $sess[__METHOD__]); + } - function testDestroy() { - $this->assertFalse(Sess::isActive()); + function testDestroy() { + $this->assertFalse(Sess::isActive()); - $session = new Sess($this->client, $this->cfg); - $session->start(); - $this->assertTrue(Sess::isActive()); + $session = new Sess($this->client, $this->cfg); + $session->start(); + $this->assertTrue(Sess::isActive()); - $_SESSION[__METHOD__] = 1; - $session->write(session_id(), $_SESSION); + $_SESSION[__METHOD__] = 1; + $session->write(session_id(), $_SESSION); - $prefix = $this->cfg->prefix . session_id(); - $this->assertTrue($this->client->exists($prefix)); + $prefix = $this->cfg->prefix . session_id(); + $this->assertTrue($this->client->exists($prefix)); - session_destroy(); - $this->assertFalse($this->client->exists($prefix)); + session_destroy(); + $this->assertFalse($this->client->exists($prefix)); - $this->assertFalse(Sess::isActive()); - } + $this->assertFalse(Sess::isActive()); } +}