diff --git a/coverage/AbstractSession.php.html b/coverage/AbstractSession.php.html
index e7b166a..72e51e4 100644
--- a/coverage/AbstractSession.php.html
+++ b/coverage/AbstractSession.php.html
@@ -57,7 +57,7 @@
- getTokenKey |
+ getTokenKey |
100.00% covered (success)
@@ -294,196 +339,1569 @@
| <?php |
| |
- | namespace AloFramework\Session; |
+
+
+
+ |
+ namespace AloFramework\Session; |
+
| |
- | use AloFramework\Common\Alo; |
- | use AloFramework\Session\AbstractSession as Sess; |
- | use InvalidArgumentException; |
- | |
- | |
- | |
- | |
- | |
- | |
- | class Token { |
- | |
- | |
- | |
- | |
- | |
- | private $tokenKey; |
- | |
- | |
- | |
- | |
- | |
- | private $name; |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | function __construct($name, $cfg = null) { |
- | if ($cfg instanceof Config) { |
- | $this->tokenKey = $cfg->tokenKey; |
- | } elseif ($cfg instanceof Sess) { |
- | $this->tokenKey = $cfg->getConfig(Config::CFG_TOKEN); |
- | } elseif ($cfg === null && $lastSession = Sess::getLastActiveSession()) { |
- | $this->tokenKey = $lastSession->getConfig(Config::CFG_TOKEN); |
- | } else { |
- | throw new InvalidArgumentException('$cfg must be an instance of ' . __NAMESPACE__ . '\\Config or ' . |
- | __NAMESPACE__ . '\\AbstractSession'); |
- | } |
- | |
- | $this->name = $name; |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | function get() { |
- | if (!Sess::isActive()) { |
- | self::sessionRequiredWarning(__METHOD__); |
- | |
- | |
- | return null; |
- | |
- | } |
- | |
- | return Alo::nullget($_SESSION[$this->tokenKey][$this->name]); |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | private static function sessionRequiredWarning($method) { |
- | trigger_error($method . ' failed: the session must be started first', E_USER_WARNING); |
- | |
- | } |
- | |
+
+
+
+ |
+ use AloFramework\Common\Alo; |
+
+
+
+
+ |
+ use AloFramework\Session\AbstractSession as Sess; |
+
+
+
+
+ |
+ use InvalidArgumentException; |
+
+
+
+
+ |
+ use JsonSerializable; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ class Token implements JsonSerializable { |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ private $tokenKey; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ private $name; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function __construct($name, $cfg = null) { |
+
+
+
+
+ |
+ if ($cfg instanceof Config) { |
+
+
+
+
+ |
+ $this->tokenKey = $cfg->tokenKey; |
+
+
+
+
+ |
+ } elseif ($cfg instanceof Sess) { |
+
+
+
+
+ |
+ $this->tokenKey = $cfg->getConfig(Config::CFG_TOKEN); |
+
+
+
+
+ |
+ } elseif ($cfg === null && $lastSession = Sess::getLastActiveSession()) { |
+
+
+
+
+ |
+ $this->tokenKey = $lastSession->getConfig(Config::CFG_TOKEN); |
+
+
+
+
+ |
+ } else { |
+
+
+
+
+ |
+ throw new InvalidArgumentException('$cfg must be an instance of ' . __NAMESPACE__ . '\\Config or ' . |
+
+
+
+
+ |
+ __NAMESPACE__ . '\\AbstractSession');
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ $this->name = $name; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function jsonSerialize() { |
+
+
+
+
+ |
+ return ['name' => $this->name, |
+
+
+
+
+ |
+ 'key' => $this->tokenKey]; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function get() { |
+
+
+
+
+ |
+ if (!Sess::isActive()) { |
+
+
+
+
+ |
+ self::sessionRequiredWarning(__METHOD__); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return null; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return Alo::nullget($_SESSION[$this->tokenKey][$this->name]); |
+
+
+
+
+ |
+ } |
+
| |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | function create($hash = 'sha256') { |
- | if (!Sess::isActive()) { |
- | self::sessionRequiredWarning(__METHOD__); |
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ private static function sessionRequiredWarning($method) { |
+
+
+
+
+ |
+ trigger_error($method . ' failed: the session must be started first', E_USER_WARNING); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+
+ |
+
| |
- | |
- | return null; |
- | |
- | } |
- | |
- | $entry = &$_SESSION[$this->tokenKey]; |
- | |
- | if (!Alo::get($entry) || !is_array($entry)) { |
- | $entry = []; |
- | } |
- | |
- | $entry[$this->name] = Alo::getUniqid($hash, __METHOD__); |
- | |
- | return $entry[$this->name]; |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | function removeAllTokens() { |
- | if (!Sess::isActive()) { |
- | self::sessionRequiredWarning(__METHOD__); |
- | |
- | } |
- | |
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function create($hash = 'sha256') { |
+
+
+
+
+ |
+ if (!Sess::isActive()) { |
+
+
+
+
+ |
+ self::sessionRequiredWarning(__METHOD__); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return null; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ $entry = &$_SESSION[$this->tokenKey]; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ if (!Alo::get($entry) || !is_array($entry)) { |
+
+
+
+
+ |
+ $entry = []; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ $entry[$this->name] = Alo::getUniqid($hash, __METHOD__); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return $entry[$this->name]; |
+
+
+
+
+ |
+ } |
+
| |
- | if (isset($_SESSION[$this->tokenKey])) { |
- | unset($_SESSION[$this->tokenKey]); |
- | |
- | return true; |
- | } |
- | |
- | return false; |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | function getAndRemove() { |
- | if (!Sess::isActive()) { |
- | self::sessionRequiredWarning(__METHOD__); |
- | |
- | |
- | return null; |
- | |
- | } |
- | |
- | $tok = Alo::nullget($_SESSION[$this->tokenKey][$this->name]); |
- | $this->remove(); |
- | |
- | return $tok; |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | function remove() { |
- | if (!Sess::isActive()) { |
- | self::sessionRequiredWarning(__METHOD__); |
- | } elseif (isset($_SESSION[$this->tokenKey][$this->name])) { |
- | unset($_SESSION[$this->tokenKey][$this->name]); |
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function removeAllTokens() { |
+
+
+
+
+ |
+ if (!Sess::isActive()) { |
+
+
+
+
+ |
+ self::sessionRequiredWarning(__METHOD__); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ if (isset($_SESSION[$this->tokenKey])) { |
+
+
+
+
+ |
+ unset($_SESSION[$this->tokenKey]); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return true; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return false; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function getAndRemove() { |
+
+
+
+
+ |
+ if (!Sess::isActive()) { |
+
+
+
+
+ |
+ self::sessionRequiredWarning(__METHOD__); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return null; |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ $tok = Alo::nullget($_SESSION[$this->tokenKey][$this->name]); |
+
+
+
+
+ |
+ $this->remove(); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return $tok; |
+
+
+
+
+ |
+ } |
+
| |
- | if (empty($_SESSION[$this->tokenKey])) { |
- | unset($_SESSION[$this->tokenKey]); |
- | } |
- | |
- | return true; |
- | } |
- | |
- | return false; |
- | } |
- | |
- | |
- | |
- | |
- | |
- | |
- | protected function getName() { |
- | return $this->name; |
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ function remove() { |
+
+
+
+
+ |
+ if (!Sess::isActive()) { |
+
+
+
+
+ |
+ self::sessionRequiredWarning(__METHOD__); |
+
+
+
+
+ |
+ } elseif (isset($_SESSION[$this->tokenKey][$this->name])) { |
+
+
+
+
+ |
+ unset($_SESSION[$this->tokenKey][$this->name]); |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ if (empty($_SESSION[$this->tokenKey])) { |
+
+
+
+
+ |
+ unset($_SESSION[$this->tokenKey]); |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ return true; |
+
| } |
| |
- | |
- | |
- | |
- | |
- | |
- | protected function getTokenKey() { |
- | return $this->tokenKey; |
- | } |
- | } |
+
+
+
+ |
+ return false; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ protected function getName() { |
+
+
+
+
+ |
+ return $this->name; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+ protected function getTokenKey() { |
+
+
+
+
+ |
+ return $this->tokenKey; |
+
+
+
+
+ |
+ } |
+
+
+
+
+ |
+ } |
+
@@ -496,7 +1914,10 @@ Legend
Dead Code
- Generated by PHP_CodeCoverage 3.0.2 using PHP 5.6.15 and PHPUnit 5.0.9 at Sat Nov 14 14:52:38 GMT 2015.
+ 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.
+
diff --git a/coverage/dashboard.html b/coverage/dashboard.html
index e4ecd84..8509101 100644
--- a/coverage/dashboard.html
+++ b/coverage/dashboard.html
@@ -136,7 +136,10 @@ Project Risks
@@ -175,7 +178,7 @@ Project Risks
.yAxis.tickFormat(d3.format('d'));
d3.select('#methodCoverageDistribution svg')
- .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,0,46], "Method Coverage"))
+ .datum(getCoverageDistributionData([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48], "Method Coverage"))
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
@@ -225,7 +228,27 @@ Project Risks
chart.yAxis.axisLabel('Cyclomatic Complexity');
d3.select('#classComplexity svg')
- .datum(getComplexityData([[100,37," AbstractSession<\/a>"],[100,3,"Config<\/a>"],[100,2,"MySQLNoEventSession<\/a>"],[100,14,"MySQLSession<\/a>"],[100,9,"RedisSession<\/a>"],[100,0,"SessionException<\/a>"],[100,23,"Token<\/a>"]], 'Class Complexity'))
+ .datum(getComplexityData([[100,
+ 39,
+ "AbstractSession<\/a>"],
+ [100,
+ 3,
+ "Config<\/a>"],
+ [100,
+ 2,
+ "MySQLNoEventSession<\/a>"],
+ [100,
+ 14,
+ "MySQLSession<\/a>"],
+ [100,
+ 9,
+ "RedisSession<\/a>"],
+ [100,
+ 0,
+ "SessionException<\/a>"],
+ [100,
+ 24,
+ "Token<\/a>"]], 'Class Complexity'))
.transition()
.duration(500)
.call(chart);
@@ -249,7 +272,150 @@ Project Risks
chart.yAxis.axisLabel('Method Complexity');
d3.select('#methodComplexity svg')
- .datum(getComplexityData([[100,1,"AbstractSession::__construct<\/a>"],[100,4,"AbstractSession::setID<\/a>"],[100,1,"AbstractSession::idExists<\/a>"],[100,2,"AbstractSession::destroySafely<\/a>"],[100,1,"AbstractSession::isActive<\/a>"],[100,1,"AbstractSession::getLastActiveSession<\/a>"],[100,2,"AbstractSession::start<\/a>"],[100,3,"AbstractSession::identityCheck<\/a>"],[100,1,"AbstractSession::getFingerprint<\/a>"],[100,1,"AbstractSession::handleIdentityCheckFailure<\/a>"],[100,1,"AbstractSession::close<\/a>"],[100,1,"AbstractSession::destroy<\/a>"],[100,1,"AbstractSession::gc<\/a>"],[100,1,"AbstractSession::open<\/a>"],[100,2,"AbstractSession::offsetExists<\/a>"],[100,1,"AbstractSession::sessionRequiredWarning<\/a>"],[100,1,"AbstractSession::__get<\/a>"],[100,1,"AbstractSession::__set<\/a>"],[100,2,"AbstractSession::offsetGet<\/a>"],[100,2,"AbstractSession::offsetSet<\/a>"],[100,2,"AbstractSession::offsetUnset<\/a>"],[100,2,"AbstractSession::__destruct<\/a>"],[100,3,"AbstractSession::shouldBeSaved<\/a>"],[100,1,"Config::__construct<\/a>"],[100,2,"Config::setDefaultConfig<\/a>"],[100,1,"MySQLNoEventSession::gc<\/a>"],[100,1,"MySQLNoEventSession::start<\/a>"],[100,1,"MySQLSession::__construct<\/a>"],[100,2,"MySQLSession::destroy<\/a>"],[100,4,"MySQLSession::idExists<\/a>"],[100,4,"MySQLSession::read<\/a>"],[100,3,"MySQLSession::write<\/a>"],[100,3,"RedisSession::__construct<\/a>"],[100,1,"RedisSession::destroy<\/a>"],[100,1,"RedisSession::idExists<\/a>"],[100,2,"RedisSession::read<\/a>"],[100,2,"RedisSession::write<\/a>"],[100,5,"Token::__construct<\/a>"],[100,2,"Token::get<\/a>"],[100,1,"Token::sessionRequiredWarning<\/a>"],[100,4,"Token::create<\/a>"],[100,3,"Token::removeAllTokens<\/a>"],[100,2,"Token::getAndRemove<\/a>"],[100,4,"Token::remove<\/a>"],[100,1,"Token::getName<\/a>"],[100,1,"Token::getTokenKey<\/a>"]], 'Method Complexity'))
+ .datum(getComplexityData([[100,
+ 1,
+ "AbstractSession::__construct<\/a>"],
+ [100,
+ 4,
+ "AbstractSession::setID<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::idExists<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::destroySafely<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::getLastActiveSession<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::jsonSerialize<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::isActive<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::start<\/a>"],
+ [100,
+ 3,
+ "AbstractSession::identityCheck<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::getFingerprint<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::handleIdentityCheckFailure<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::close<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::destroy<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::gc<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::open<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::offsetExists<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::sessionRequiredWarning<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::__get<\/a>"],
+ [100,
+ 1,
+ "AbstractSession::__set<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::offsetGet<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::offsetSet<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::offsetUnset<\/a>"],
+ [100,
+ 2,
+ "AbstractSession::__destruct<\/a>"],
+ [100,
+ 3,
+ "AbstractSession::shouldBeSaved<\/a>"],
+ [100,
+ 1,
+ "Config::__construct<\/a>"],
+ [100,
+ 2,
+ "Config::setDefaultConfig<\/a>"],
+ [100,
+ 1,
+ "MySQLNoEventSession::gc<\/a>"],
+ [100,
+ 1,
+ "MySQLNoEventSession::start<\/a>"],
+ [100,
+ 1,
+ "MySQLSession::__construct<\/a>"],
+ [100,
+ 2,
+ "MySQLSession::destroy<\/a>"],
+ [100,
+ 4,
+ "MySQLSession::read<\/a>"],
+ [100,
+ 3,
+ "MySQLSession::write<\/a>"],
+ [100,
+ 4,
+ "MySQLSession::idExists<\/a>"],
+ [100,
+ 3,
+ "RedisSession::__construct<\/a>"],
+ [100,
+ 1,
+ "RedisSession::destroy<\/a>"],
+ [100,
+ 2,
+ "RedisSession::read<\/a>"],
+ [100,
+ 2,
+ "RedisSession::write<\/a>"],
+ [100,
+ 1,
+ "RedisSession::idExists<\/a>"],
+ [100,
+ 5,
+ "Token::__construct<\/a>"],
+ [100,
+ 1,
+ "Token::jsonSerialize<\/a>"],
+ [100,
+ 2,
+ "Token::get<\/a>"],
+ [100,
+ 1,
+ "Token::sessionRequiredWarning<\/a>"],
+ [100,
+ 4,
+ "Token::create<\/a>"],
+ [100,
+ 3,
+ "Token::removeAllTokens<\/a>"],
+ [100,
+ 2,
+ "Token::getAndRemove<\/a>"],
+ [100,
+ 4,
+ "Token::remove<\/a>"],
+ [100,
+ 1,
+ "Token::getName<\/a>"],
+ [100,
+ 1,
+ "Token::getTokenKey<\/a>"]], 'Method Complexity'))
.transition()
.duration(500)
.call(chart);
diff --git a/coverage/index.html b/coverage/index.html
index 9b9f776..1f25bad 100644
--- a/coverage/index.html
+++ b/coverage/index.html
@@ -49,7 +49,9 @@
|
100.00% |
- 164 / 164 |
+
+ 169 / 169
+ |
100.00% covered (success)
@@ -57,7 +59,9 @@
|
100.00% |
- 42 / 42 |
+
+ 44 / 44
+ |
100.00% covered (success)
@@ -77,7 +81,9 @@
|
100.00% |
- 64 / 64 |
+
+ 67 / 67
+ |
100.00% covered (success)
@@ -85,7 +91,9 @@
|
100.00% |
- 19 / 19 |
+
+ 20 / 20
+ |
100.00% covered (success)
@@ -161,7 +169,9 @@
|
100.00% |
- 19 / 19 |
+
+ 18 / 18
+ |
100.00% covered (success)
@@ -189,7 +199,9 @@
|
100.00% |
- 12 / 12 |
+
+ 13 / 13
+ |
100.00% covered (success)
@@ -245,7 +257,9 @@
|
100.00% |
- 45 / 45 |
+
+ 47 / 47
+ |
100.00% covered (success)
@@ -253,7 +267,9 @@
|
100.00% |
- 9 / 9 |
+
+ 10 / 10
+ |
diff --git a/src/RedisSession.php b/src/RedisSession.php
index 893754b..9794021 100644
--- a/src/RedisSession.php
+++ b/src/RedisSession.php
@@ -99,7 +99,9 @@ function write($sessionID, $sessionData) {
$sessionData);
}
+ // @codeCoverageIgnoreStart
return true;
+ // @codeCoverageIgnoreEnd
}
/**
diff --git a/tests/AbstractSessionTest.php b/tests/AbstractSessionTest.php
index 86bf8b9..dc217da 100644
--- a/tests/AbstractSessionTest.php
+++ b/tests/AbstractSessionTest.php
@@ -1,203 +1,211 @@
cfg = new Cfg([Cfg::CFG_SECURE => false,
- Cfg::CFG_SAVE_CLI => true]);
- }
+ /** @var Redis */
+ private $redis;
- function checkSouldBeSaved() {
- $red = new \Redis();
- $red->connect('127.0.0.1');
+ 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->redis = new Redis();
+ $this->redis->connect('127.0.0.1');
+ }
- $sess = new ProtectedChecks($red, $this->cfg);
- $this->assertTrue($sess->shouldBeSavedCheck());
- $sess->addConfig(Cfg::CFG_SAVE_CLI, false);
- $this->assertFalse($sess->shouldBeSavedCheck());
- }
+ function checkSouldBeSaved() {
+ $sess = new ProtectedChecks($this->redis, $this->cfg);
+ $this->assertTrue($sess->shouldBeSavedCheck());
+ $sess->addConfig(Cfg::CFG_SAVE_CLI, false);
+ $this->assertFalse($sess->shouldBeSavedCheck());
+ }
- function testgetLastActiveSession() {
- $red = new \Redis();
- $red->connect('127.0.0.1');
-
- $this->assertNull(Sess::getLastActiveSession());
-
- (new Sess($red,$this->cfg))->start();
- $this->assertTrue(Sess::getLastActiveSession() instanceof Sess);
- session_write_close();
- $this->assertNull(Sess::getLastActiveSession());
-
- (new Sess($red,$this->cfg))->start();
- $this->assertTrue(Sess::getLastActiveSession() instanceof Sess);
- session_destroy();
- $this->assertNull(Sess::getLastActiveSession());
- }
+ function testgetLastActiveSession() {
+ $this->assertNull(Sess::getLastActiveSession());
- function testDestruct() {
- $red = new \Redis();
- $red->connect('127.0.0.1');
- $sess = new Sess($red, $this->cfg);
+ (new Sess($this->redis, $this->cfg))->start();
+ $this->assertTrue(Sess::getLastActiveSession() instanceof Sess);
+ session_write_close();
+ $this->assertNull(Sess::getLastActiveSession());
- $this->assertFalse(Sess::isActive());
- $sess->start();
- $this->assertTrue(Sess::isActive());
+ (new Sess($this->redis, $this->cfg))->start();
+ $this->assertTrue(Sess::getLastActiveSession() instanceof Sess);
+ session_destroy();
+ $this->assertNull(Sess::getLastActiveSession());
+ }
- $key = $this->cfg->prefix . session_id();
- $this->assertFalse($red->exists($key));
+ function testDestruct() {
+ $sess = new Sess($this->redis, $this->cfg);
- $_SESSION[__METHOD__] = 'foo';
- $sess->__destruct();
- $this->assertEquals('s:3:"foo"', self::sessionUnserialize($red->get($key))[__METHOD__]);
- }
+ $this->assertFalse(Sess::isActive());
+ $sess->start();
+ $this->assertTrue(Sess::isActive());
- protected static function sessionUnserialize($str) {
- $spl = explode(';', $str);
+ $key = $this->cfg->prefix . session_id();
+ $this->assertFalse($this->redis->exists($key));
- foreach ($spl as $k => $s) {
- if (trim($s)) {
- $s = explode('|', $s);
- $spl[$s[0]] = $s[1];
- }
- unset($spl[$k]);
- }
+ $_SESSION[__METHOD__] = 'foo';
+ $sess->__destruct();
+ $this->assertEquals('s:3:"foo"', self::sessionUnserialize($this->redis->get($key))[__METHOD__]);
+ }
- return $spl;
- }
+ protected static function sessionUnserialize($str) {
+ $spl = explode(';', $str);
- function testDestroySafely() {
- $this->assertFalse(Sess::isActive());
- $this->assertFalse(Sess::destroySafely());
- (new Sess(null, $this->cfg))->start();
- $this->assertTrue(Sess::isActive());
- $this->assertTrue(Sess::destroySafely());
- $this->assertFalse(Sess::isActive());
+ foreach ($spl as $k => $s) {
+ if (trim($s)) {
+ $s = explode('|', $s);
+ $spl[$s[0]] = $s[1];
+ }
+ unset($spl[$k]);
}
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testStartDuplicate() {
- $red = new \Redis();
- $red->connect('127.0.0.1');
+ return $spl;
+ }
- (new Sess($red, $this->cfg))->start();
- (new Sess($red, $this->cfg))->start();
- }
+ function testJsonSerializeNoSession() {
+ $sess = new Sess($this->redis, $this->cfg);
+ $this->assertEquals(json_encode([]), json_encode($sess));
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningIsset() {
- $s = new Sess(null, $this->cfg);
+ function testJsonSerializeSession() {
+ $sess = new Sess($this->redis, $this->cfg);
+ $sess->start();
+ $finger = (new Config())->get(Config::CFG_FINGERPRINT_NAME);
+ $_SESSION[__METHOD__] = 'bar';
+ $pattern = '~{"' . $finger . '":"[a-z0-9]{32}","' . __METHOD__ . '":"bar"}~i';
+ $str = json_encode($sess);
- isset($s['foo']);
- }
+ $this->assertEquals(1, preg_match($pattern, $str));
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningUnset() {
- $s = new Sess(null, $this->cfg);
+ function testDestroySafely() {
+ $this->assertFalse(Sess::isActive());
+ $this->assertFalse(Sess::destroySafely());
+ (new Sess(null, $this->cfg))->start();
+ $this->assertTrue(Sess::isActive());
+ $this->assertTrue(Sess::destroySafely());
+ $this->assertFalse(Sess::isActive());
+ }
- unset($s['foo']);
- }
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testStartDuplicate() {
+ (new Sess($this->redis, $this->cfg))->start();
+ (new Sess($this->redis, $this->cfg))->start();
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningOffsetGet() {
- $s = new Sess(null, $this->cfg);
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningIsset() {
+ $s = new Sess(null, $this->cfg);
- $s['foo'];
- }
+ /** @noinspection PhpExpressionResultUnusedInspection */
+ isset($s['foo']);
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningMagicGet() {
- $s = new Sess(null, $this->cfg);
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningUnset() {
+ $s = new Sess(null, $this->cfg);
- $s->foo;
- }
+ unset($s['foo']);
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningOffsetSet() {
- $s = new Sess(null, $this->cfg);
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningOffsetGet() {
+ $s = new Sess(null, $this->cfg);
- $s['foo'] = 'bar';
- }
+ $s['foo'];
+ }
- /**
- * @expectedException \PHPUnit_Framework_Error
- */
- function testSessionRequiredWarningMagicSet() {
- $s = new Sess(null, $this->cfg);
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningMagicGet() {
+ $s = new Sess(null, $this->cfg);
- $s->foo = 'bar';
- }
+ $s->foo;
+ }
- function testBadIdentityCheck() {
- /** @var ProtectedChecks $sess */
- $red = new \Redis();
- $red->connect('127.0.0.1');
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningOffsetSet() {
+ $s = new Sess(null, $this->cfg);
- $this->assertFalse(Sess::isActive());
- $sess = (new ProtectedChecks($red, $this->cfg))->start();
- $sid = session_id();
- $prefix = $this->cfg->prefix . $sid;
- $_SESSION[__METHOD__] = 1;
- $sess->write($sid, $_SESSION);
+ $s['foo'] = 'bar';
+ }
- $this->assertTrue(Sess::isActive());
- $this->assertTrue($red->exists($prefix));
+ /**
+ * @expectedException \PHPUnit_Framework_Error
+ */
+ function testSessionRequiredWarningMagicSet() {
+ $s = new Sess(null, $this->cfg);
- $sess->idCheck($sid);
+ $s->foo = 'bar';
+ }
- $this->assertFalse(Sess::isActive());
- $this->assertFalse($red->exists($prefix));
- }
+ function testBadIdentityCheck() {
+ /** @var ProtectedChecks $sess */
- function testMagic() {
- $red = new \Redis();
- $red->connect('127.0.0.1');
+ $this->assertFalse(Sess::isActive());
+ $sess = (new ProtectedChecks($this->redis, $this->cfg))->start();
+ $sid = session_id();
+ $prefix = $this->cfg->prefix . $sid;
+ $_SESSION[__METHOD__] = 1;
+ $sess->write($sid, $_SESSION);
- $sess = (new Sess($red, $this->cfg))->start();
- $sess['one'] = 'foo';
- $sess->two = 'bar';
+ $this->assertTrue(Sess::isActive());
+ $this->assertTrue($this->redis->exists($prefix));
- $this->assertTrue(isset($sess['one']));
- $this->assertTrue(isset($_SESSION['one']));
+ $sess->idCheck($sid);
- $this->assertEquals('foo', $sess->{'one'});
- $this->assertEquals('bar', $sess['two']);
- $this->assertEquals('foo', $_SESSION['one']);
- $this->assertEquals('bar', $_SESSION['two']);
+ $this->assertFalse(Sess::isActive());
+ $this->assertFalse($this->redis->exists($prefix));
+ }
- unset($sess['two']);
- $this->assertFalse(isset($_SESSION['two']));
- }
+ function testMagic() {
+ $sess = (new Sess($this->redis, $this->cfg))->start();
+ $sess['one'] = 'foo';
+ $sess->two = 'bar';
+
+ $this->assertTrue(isset($sess['one']));
+ $this->assertTrue(isset($_SESSION['one']));
+
+ $this->assertEquals('foo', $sess->{'one'});
+ $this->assertEquals('bar', $sess['two']);
+ $this->assertEquals('foo', $_SESSION['one']);
+ $this->assertEquals('bar', $_SESSION['two']);
+
+ unset($sess['two']);
+ $this->assertFalse(isset($_SESSION['two']));
}
+}
- class ProtectedChecks extends Sess {
+class ProtectedChecks extends Sess {
- function idCheck($sessionID) {
- parent::handleIdentityCheckFailure($sessionID);
- }
+ function idCheck($sessionID) {
+ parent::handleIdentityCheckFailure($sessionID);
+ }
- function shouldBeSavedCheck() {
- return $this->shouldBeSaved();
- }
+ function shouldBeSavedCheck() {
+ return $this->shouldBeSaved();
}
+}
diff --git a/tests/TokenTest.php b/tests/TokenTest.php
index 7b05676..1e814aa 100644
--- a/tests/TokenTest.php
+++ b/tests/TokenTest.php
@@ -1,179 +1,188 @@
redis = new Redis();
- $this->redis->connect('127.0.0.1');
- $this->cfg = new Config();
- $this->key = $this->cfg->tokenKey;
- }
+namespace AloFramework\Session\Tests;
+
+use AloFramework\Session\Config;
+use AloFramework\Session\RedisSession as Sess;
+use AloFramework\Session\Token;
+use PHPUnit_Framework_TestCase;
+use Redis;
+
+class TokenTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Redis
+ */
+ private $redis;
+
+ /**
+ * @var string
+ */
+ private $key;
+
+ /** @var Config */
+ private $cfg;
+
+ function __construct($name = null, array $data = [], $dataName = '') {
+ parent::__construct($name, $data, $dataName);
+ $this->redis = new Redis();
+ $this->redis->connect('127.0.0.1');
+ $this->cfg = new Config();
+ $this->key = $this->cfg->tokenKey;
+ }
- function testConstructWithConfigObject() {
- $tok = new TokenProtectedMethods(__METHOD__, $this->cfg);
+ function testConstructWithConfigObject() {
+ $tok = new TokenProtectedMethods(__METHOD__, $this->cfg);
- $this->assertEquals($this->key, $tok->getKeyTest());
- $this->assertEquals(__METHOD__, $tok->getNameTest());
- }
+ $this->assertEquals($this->key, $tok->getKeyTest());
+ $this->assertEquals(__METHOD__, $tok->getNameTest());
+ }
- function testConstructWithSessionObject() {
- $tok = new TokenProtectedMethods(__METHOD__, $this->sess());
- $this->assertEquals($this->key, $tok->getKeyTest());
- }
+ function testConstructWithSessionObject() {
+ $tok = new TokenProtectedMethods(__METHOD__, $this->sess());
+ $this->assertEquals($this->key, $tok->getKeyTest());
+ }
- function testConstructNull() {
- $this->sess();
- $tok = new TokenProtectedMethods(__METHOD__);
- $this->assertEquals($this->key, $tok->getKeyTest());
- }
+ private function sess() {
+ Sess::destroySafely();
- function testConstructNullNoSession() {
- Sess::destroySafely();
- $this->setExpectedException('\InvalidArgumentException');
- new TokenProtectedMethods(__METHOD__);
- }
+ return (new Sess($this->redis))->start();
+ }
- /** @dataProvider methodSessionWarningsProvider */
- function testMethodSessionWarnings($method) {
- Sess::destroySafely();
- $this->setExpectedException('\PHPUnit_Framework_Error');
- $tok = new Token('foo', $this->cfg);
+ function testConstructNull() {
+ $this->sess();
+ $tok = new TokenProtectedMethods(__METHOD__);
+ $this->assertEquals($this->key, $tok->getKeyTest());
+ }
- call_user_func([$tok, $method]);
- }
+ function testJsonEncode() {
+ $token = new Token(__METHOD__, $this->cfg);
+ $this->assertEquals(json_encode([
+ 'name' => __METHOD__,
+ 'key' => $this->cfg->tokenKey
+ ]),
+ json_encode($token));
+ }
- function testCreate() {
- $this->sess();
- $tok = new Token(__METHOD__, $this->cfg);
- $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ function testConstructNullNoSession() {
+ Sess::destroySafely();
+ $this->setExpectedException('\InvalidArgumentException');
+ new TokenProtectedMethods(__METHOD__);
+ }
- $token = $tok->create('sha512');
- $this->assertEquals(strlen(hash('sha512', 1)), strlen($token));
- $this->assertTrue(array_key_exists($this->key, $_SESSION));
+ /** @dataProvider methodSessionWarningsProvider */
+ function testMethodSessionWarnings($method) {
+ Sess::destroySafely();
+ $this->setExpectedException('\PHPUnit_Framework_Error');
+ $tok = new Token('foo', $this->cfg);
- $this->assertTrue(array_key_exists(__METHOD__, $_SESSION[$this->key]));
- $this->assertEquals($token, $_SESSION[$this->key][__METHOD__]);
- }
+ call_user_func([$tok, $method]);
+ }
- function testGet() {
- $this->sess();
- $tok = new Token(__METHOD__, $this->cfg);
- $this->assertTrue($tok->get() === null);
+ function testCreate() {
+ $this->sess();
+ $tok = new Token(__METHOD__, $this->cfg);
+ $this->assertFalse(array_key_exists($this->key, $_SESSION));
- $create = $tok->create();
+ $token = $tok->create('sha512');
+ $this->assertEquals(strlen(hash('sha512', 1)), strlen($token));
+ $this->assertTrue(array_key_exists($this->key, $_SESSION));
- $this->assertEquals($create, $tok->get());
- }
+ $this->assertTrue(array_key_exists(__METHOD__, $_SESSION[$this->key]));
+ $this->assertEquals($token, $_SESSION[$this->key][__METHOD__]);
+ }
- function testRemove() {
- $this->sess();
- $tok = new Token(__METHOD__, $this->cfg);
+ function testGet() {
+ $this->sess();
+ $tok = new Token(__METHOD__, $this->cfg);
+ $this->assertTrue($tok->get() === null);
- $this->assertFalse($tok->remove());
- $tok->create();
- $this->assertTrue($tok->remove());
- }
+ $create = $tok->create();
+
+ $this->assertEquals($create, $tok->get());
+ }
- function testRemoveMultiple() {
- $this->sess();
- $tok1 = new Token(__METHOD__ . '1', $this->cfg);
- $tok2 = new Token(__METHOD__ . '2', $this->cfg);
+ function testRemove() {
+ $this->sess();
+ $tok = new Token(__METHOD__, $this->cfg);
- $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ $this->assertFalse($tok->remove());
+ $tok->create();
+ $this->assertTrue($tok->remove());
+ }
- $tok1->create();
- $tok2->create();
+ function testRemoveMultiple() {
+ $this->sess();
+ $tok1 = new Token(__METHOD__ . '1', $this->cfg);
+ $tok2 = new Token(__METHOD__ . '2', $this->cfg);
- $this->assertTrue(array_key_exists($this->key, $_SESSION));
- $this->assertTrue(array_key_exists(__METHOD__ . '1', $_SESSION[$this->key]));
- $this->assertTrue(array_key_exists(__METHOD__ . '2', $_SESSION[$this->key]));
+ $this->assertFalse(array_key_exists($this->key, $_SESSION));
- $tok1->remove();
- $this->assertTrue(array_key_exists($this->key, $_SESSION));
- $this->assertFalse(array_key_exists(__METHOD__ . '1', $_SESSION[$this->key]));
- $this->assertTrue(array_key_exists(__METHOD__ . '2', $_SESSION[$this->key]));
+ $tok1->create();
+ $tok2->create();
- $tok2->remove();
- $this->assertFalse(array_key_exists($this->key, $_SESSION));
- }
+ $this->assertTrue(array_key_exists($this->key, $_SESSION));
+ $this->assertTrue(array_key_exists(__METHOD__ . '1', $_SESSION[$this->key]));
+ $this->assertTrue(array_key_exists(__METHOD__ . '2', $_SESSION[$this->key]));
- function testRemoveAllTokens() {
- $this->sess();
- /** @var Token[] $toks */
- $toks = [];
+ $tok1->remove();
+ $this->assertTrue(array_key_exists($this->key, $_SESSION));
+ $this->assertFalse(array_key_exists(__METHOD__ . '1', $_SESSION[$this->key]));
+ $this->assertTrue(array_key_exists(__METHOD__ . '2', $_SESSION[$this->key]));
- $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ $tok2->remove();
+ $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ }
- for ($i = 0; $i < 5; $i++) {
- $tok = new Token(__METHOD__ . $i, $this->cfg);
- $tok->create('md5');
- $toks[] = $tok;
- }
+ function testRemoveAllTokens() {
+ $this->sess();
+ /** @var Token[] $toks */
+ $toks = [];
- foreach ($toks as $tok) {
- $this->assertEquals(32, strlen($tok->get()));
- }
+ $this->assertFalse(array_key_exists($this->key, $_SESSION));
- $this->assertTrue($toks[0]->removeAllTokens());
- $this->assertFalse($toks[0]->removeAllTokens());
- $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ for ($i = 0; $i < 5; $i++) {
+ $tok = new Token(__METHOD__ . $i, $this->cfg);
+ $tok->create('md5');
+ $toks[] = $tok;
}
- function testGetAndRemove() {
- $this->sess();
- $tok = new Token(__METHOD__, $this->cfg);
- $this->assertTrue($tok->get() === null);
+ foreach ($toks as $tok) {
+ $this->assertEquals(32, strlen($tok->get()));
+ }
- $create = $tok->create();
- $this->assertEquals($create, $tok->getAndRemove());
+ $this->assertTrue($toks[0]->removeAllTokens());
+ $this->assertFalse($toks[0]->removeAllTokens());
+ $this->assertFalse(array_key_exists($this->key, $_SESSION));
+ }
- $this->assertTrue($tok->get() === null);
- }
+ function testGetAndRemove() {
+ $this->sess();
+ $tok = new Token(__METHOD__, $this->cfg);
+ $this->assertTrue($tok->get() === null);
- function methodSessionWarningsProvider() {
- return [['get'],
- ['create'],
- ['remove'],
- ['removeAllTokens'],
- ['getAndRemove']];
- }
+ $create = $tok->create();
+ $this->assertEquals($create, $tok->getAndRemove());
- private function sess() {
- Sess::destroySafely();
+ $this->assertTrue($tok->get() === null);
+ }
- return (new Sess($this->redis))->start();
- }
+ function methodSessionWarningsProvider() {
+ return [['get'],
+ ['create'],
+ ['remove'],
+ ['removeAllTokens'],
+ ['getAndRemove']];
}
+}
- class TokenProtectedMethods extends Token {
+class TokenProtectedMethods extends Token {
- function getNameTest() {
- return $this->getName();
- }
+ function getNameTest() {
+ return $this->getName();
+ }
- function getKeyTest() {
- return $this->getTokenKey();
- }
+ function getKeyTest() {
+ return $this->getTokenKey();
}
+}
|