Merge pull request #16435 from mauriciofauth/session-cache

Extract cache methods from Util to SessionCache class
This commit is contained in:
Maurício Meneghini Fauth 2020-10-26 17:56:13 -03:00 committed by GitHub
commit fca77d1f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 225 additions and 212 deletions

View File

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\Utils\SessionCache;
use function mb_strpos;
use function mb_substr;
use function preg_match;
@ -169,33 +170,33 @@ class CheckUserPrivileges
*/
private function analyseShowGrant(): void
{
if (Util::cacheExists('is_create_db_priv')) {
$GLOBALS['is_create_db_priv'] = Util::cacheGet(
if (SessionCache::has('is_create_db_priv')) {
$GLOBALS['is_create_db_priv'] = SessionCache::get(
'is_create_db_priv'
);
$GLOBALS['is_reload_priv'] = Util::cacheGet(
$GLOBALS['is_reload_priv'] = SessionCache::get(
'is_reload_priv'
);
$GLOBALS['db_to_create'] = Util::cacheGet(
$GLOBALS['db_to_create'] = SessionCache::get(
'db_to_create'
);
$GLOBALS['dbs_where_create_table_allowed'] = Util::cacheGet(
$GLOBALS['dbs_where_create_table_allowed'] = SessionCache::get(
'dbs_where_create_table_allowed'
);
$GLOBALS['dbs_to_test'] = Util::cacheGet(
$GLOBALS['dbs_to_test'] = SessionCache::get(
'dbs_to_test'
);
$GLOBALS['db_priv'] = Util::cacheGet(
$GLOBALS['db_priv'] = SessionCache::get(
'db_priv'
);
$GLOBALS['col_priv'] = Util::cacheGet(
$GLOBALS['col_priv'] = SessionCache::get(
'col_priv'
);
$GLOBALS['table_priv'] = Util::cacheGet(
$GLOBALS['table_priv'] = SessionCache::get(
'table_priv'
);
$GLOBALS['proc_priv'] = Util::cacheGet(
$GLOBALS['proc_priv'] = SessionCache::get(
'proc_priv'
);
@ -324,19 +325,19 @@ class CheckUserPrivileges
// must also cacheUnset() them in
// PhpMyAdmin\Plugins\Auth\AuthenticationCookie
Util::cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv']);
Util::cacheSet('is_reload_priv', $GLOBALS['is_reload_priv']);
Util::cacheSet('db_to_create', $GLOBALS['db_to_create']);
Util::cacheSet(
SessionCache::set('is_create_db_priv', $GLOBALS['is_create_db_priv']);
SessionCache::set('is_reload_priv', $GLOBALS['is_reload_priv']);
SessionCache::set('db_to_create', $GLOBALS['db_to_create']);
SessionCache::set(
'dbs_where_create_table_allowed',
$GLOBALS['dbs_where_create_table_allowed']
);
Util::cacheSet('dbs_to_test', $GLOBALS['dbs_to_test']);
SessionCache::set('dbs_to_test', $GLOBALS['dbs_to_test']);
Util::cacheSet('proc_priv', $GLOBALS['proc_priv']);
Util::cacheSet('table_priv', $GLOBALS['table_priv']);
Util::cacheSet('col_priv', $GLOBALS['col_priv']);
Util::cacheSet('db_priv', $GLOBALS['db_priv']);
SessionCache::set('proc_priv', $GLOBALS['proc_priv']);
SessionCache::set('table_priv', $GLOBALS['table_priv']);
SessionCache::set('col_priv', $GLOBALS['col_priv']);
SessionCache::set('db_priv', $GLOBALS['db_priv']);
}
/**

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\Navigation\Navigation;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
/**
* The navigation panel
@ -60,7 +60,7 @@ class NavigationController extends AbstractController
}
if (isset($_POST['reload'])) {
Util::cacheSet('dbs_to_test', false);// Empty database list cache, see #14252
SessionCache::set('dbs_to_test', false);// Empty database list cache, see #14252
}
$cfgRelation = $this->relation->getRelationsParam();

View File

@ -18,6 +18,7 @@ use PhpMyAdmin\Query\Compatibility;
use PhpMyAdmin\Query\Generator as QueryGenerator;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\Utils\SessionCache;
use const E_USER_WARNING;
use const LOG_INFO;
use const LOG_NDELAY;
@ -1735,12 +1736,12 @@ class DatabaseInterface implements DbalInterface
*/
public function getCurrentUser(): string
{
if (Util::cacheExists('mysql_cur_user')) {
return Util::cacheGet('mysql_cur_user');
if (SessionCache::has('mysql_cur_user')) {
return SessionCache::get('mysql_cur_user');
}
$user = $this->fetchValue('SELECT CURRENT_USER();');
if ($user !== false) {
Util::cacheSet('mysql_cur_user', $user);
SessionCache::set('mysql_cur_user', $user);
return $user;
}
@ -1750,8 +1751,8 @@ class DatabaseInterface implements DbalInterface
public function isSuperUser(): bool
{
if (Util::cacheExists('is_superuser')) {
return Util::cacheGet('is_superuser');
if (SessionCache::has('is_superuser')) {
return SessionCache::get('is_superuser');
}
if (! $this->isConnected()) {
@ -1770,7 +1771,7 @@ class DatabaseInterface implements DbalInterface
}
$this->freeResult($result);
Util::cacheSet('is_superuser', $isSuperUser);
SessionCache::set('is_superuser', $isSuperUser);
return $isSuperUser;
}
@ -1779,8 +1780,8 @@ class DatabaseInterface implements DbalInterface
{
global $cfg;
if (Util::cacheExists('is_grantuser')) {
return Util::cacheGet('is_grantuser');
if (SessionCache::has('is_grantuser')) {
return SessionCache::get('is_grantuser');
}
if (! $this->isConnected()) {
@ -1799,7 +1800,7 @@ class DatabaseInterface implements DbalInterface
}
}
Util::cacheSet('is_grantuser', $hasGrantPrivilege);
SessionCache::set('is_grantuser', $hasGrantPrivilege);
return $hasGrantPrivilege;
}
@ -1813,7 +1814,7 @@ class DatabaseInterface implements DbalInterface
}
$this->freeResult($result);
Util::cacheSet('is_grantuser', $hasGrantPrivilege);
SessionCache::set('is_grantuser', $hasGrantPrivilege);
return $hasGrantPrivilege;
}
@ -1822,8 +1823,8 @@ class DatabaseInterface implements DbalInterface
{
global $cfg;
if (Util::cacheExists('is_createuser')) {
return Util::cacheGet('is_createuser');
if (SessionCache::has('is_createuser')) {
return SessionCache::get('is_createuser');
}
if (! $this->isConnected()) {
@ -1844,7 +1845,7 @@ class DatabaseInterface implements DbalInterface
}
}
Util::cacheSet('is_createuser', $hasCreatePrivilege);
SessionCache::set('is_createuser', $hasCreatePrivilege);
return $hasCreatePrivilege;
}
@ -1858,7 +1859,7 @@ class DatabaseInterface implements DbalInterface
}
$this->freeResult($result);
Util::cacheSet('is_createuser', $hasCreatePrivilege);
SessionCache::set('is_createuser', $hasCreatePrivilege);
return $hasCreatePrivilege;
}
@ -2319,13 +2320,13 @@ class DatabaseInterface implements DbalInterface
*/
public function isAmazonRds(): bool
{
if (Util::cacheExists('is_amazon_rds')) {
return Util::cacheGet('is_amazon_rds');
if (SessionCache::has('is_amazon_rds')) {
return SessionCache::get('is_amazon_rds');
}
$sql = 'SELECT @@basedir';
$result = $this->fetchValue($sql);
$rds = (substr($result, 0, 10) === '/rdsdbbin/');
Util::cacheSet('is_amazon_rds', $rds);
SessionCache::set('is_amazon_rds', $rds);
return $rds;
}

View File

@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\Utils\SessionCache;
use function array_key_exists;
use function count;
use function in_array;
@ -139,8 +140,8 @@ class Menu
global $dbi;
$cache_key = 'menu-levels-' . $level;
if (Util::cacheExists($cache_key)) {
return Util::cacheGet($cache_key);
if (SessionCache::has($cache_key)) {
return SessionCache::get($cache_key);
}
$allowedTabs = Util::getMenuTabList($level);
$cfgRelation = $this->relation->getRelationsParam();
@ -169,7 +170,7 @@ class Menu
}
}
}
Util::cacheSet($cache_key, $allowedTabs);
SessionCache::set($cache_key, $allowedTabs);
return $allowedTabs;
}
@ -506,8 +507,8 @@ class Menu
$is_superuser = $dbi->isSuperUser();
$isCreateOrGrantUser = $dbi->isGrantUser() || $dbi->isCreateUser();
if (Util::cacheExists('binary_logs')) {
$binary_logs = Util::cacheGet('binary_logs');
if (SessionCache::has('binary_logs')) {
$binary_logs = SessionCache::get('binary_logs');
} else {
$binary_logs = $dbi->fetchResult(
'SHOW MASTER LOGS',
@ -516,7 +517,7 @@ class Menu
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_STORE
);
Util::cacheSet('binary_logs', $binary_logs);
SessionCache::set('binary_logs', $binary_logs);
}
$tabs = [];

View File

@ -18,6 +18,7 @@ use PhpMyAdmin\Session;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
use phpseclib\Crypt;
use phpseclib\Crypt\Random;
use ReCaptcha;
@ -405,15 +406,15 @@ class AuthenticationCookie extends AuthenticationPlugin
}
// All sessions expired
if (empty($_SESSION['browser_access_time'])) {
Util::cacheUnset('is_create_db_priv');
Util::cacheUnset('is_reload_priv');
Util::cacheUnset('db_to_create');
Util::cacheUnset('dbs_where_create_table_allowed');
Util::cacheUnset('dbs_to_test');
Util::cacheUnset('db_priv');
Util::cacheUnset('col_priv');
Util::cacheUnset('table_priv');
Util::cacheUnset('proc_priv');
SessionCache::remove('is_create_db_priv');
SessionCache::remove('is_reload_priv');
SessionCache::remove('db_to_create');
SessionCache::remove('dbs_where_create_table_allowed');
SessionCache::remove('dbs_to_test');
SessionCache::remove('db_priv');
SessionCache::remove('col_priv');
SessionCache::remove('table_priv');
SessionCache::remove('proc_priv');
$this->showFailure('no-activity');
if (! defined('TESTSUITE')) {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\Utils\SessionCache;
use function is_array;
/**
@ -13,8 +14,8 @@ final class Profiling
{
public static function isSupported(DatabaseInterface $dbi): bool
{
if (Util::cacheExists('profiling_supported')) {
return Util::cacheGet('profiling_supported');
if (SessionCache::has('profiling_supported')) {
return SessionCache::get('profiling_supported');
}
/**
@ -23,12 +24,12 @@ final class Profiling
* and do not set a constant as we might be switching servers
*/
if ($dbi->fetchValue('SELECT @@have_profiling')) {
Util::cacheSet('profiling_supported', true);
SessionCache::set('profiling_supported', true);
return true;
}
Util::cacheSet('profiling_supported', false);
SessionCache::set('profiling_supported', false);
return false;
}

View File

@ -20,6 +20,7 @@ use PhpMyAdmin\Engines\Ndbcluster;
use PhpMyAdmin\Engines\Pbxt;
use PhpMyAdmin\Engines\PerformanceSchema;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Utils\SessionCache;
use function array_key_exists;
use function define;
use function explode;
@ -106,7 +107,7 @@ class StorageEngine
if ($storage_engines == null) {
$storage_engines = $dbi->fetchResult('SHOW STORAGE ENGINES', 'Engine');
if ($dbi->getVersion() >= 50708) {
$disabled = (string) Util::cacheGet(
$disabled = (string) SessionCache::get(
'disabled_storage_engines',
static function () use ($dbi) {
return $dbi->fetchValue(

View File

@ -4,13 +4,13 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use Closure;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\SqlParser\Components\Expression;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\Utils\SessionCache;
use phpseclib\Crypt\Random;
use stdClass;
use const ENT_COMPAT;
@ -1348,76 +1348,9 @@ class Util
*/
public static function clearUserCache(): void
{
self::cacheUnset('is_superuser');
self::cacheUnset('is_createuser');
self::cacheUnset('is_grantuser');
}
/**
* Calculates session cache key
*/
public static function cacheKey(): string
{
if (isset($GLOBALS['cfg']['Server']['user'])) {
return 'server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user'];
}
return 'server_' . $GLOBALS['server'];
}
/**
* Verifies if something is cached in the session
*
* @param string $var variable name
*/
public static function cacheExists($var): bool
{
return isset($_SESSION['cache'][self::cacheKey()][$var]);
}
/**
* Gets cached information from the session
*
* @param string $var variable name
* @param Closure $callback callback to fetch the value
*
* @return mixed
*/
public static function cacheGet($var, $callback = null)
{
if (self::cacheExists($var)) {
return $_SESSION['cache'][self::cacheKey()][$var];
}
if ($callback) {
$val = $callback();
self::cacheSet($var, $val);
return $val;
}
return null;
}
/**
* Caches information in the session
*
* @param string $var variable name
* @param mixed $val value
*/
public static function cacheSet($var, $val = null): void
{
$_SESSION['cache'][self::cacheKey()][$var] = $val;
}
/**
* Removes cached information from the session
*
* @param string $var variable name
*/
public static function cacheUnset($var): void
{
unset($_SESSION['cache'][self::cacheKey()][$var]);
SessionCache::remove('is_superuser');
SessionCache::remove('is_createuser');
SessionCache::remove('is_grantuser');
}
/**

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Utils;
final class SessionCache
{
private static function key(): string
{
global $cfg, $server;
$key = 'server_' . $server;
if (isset($cfg['Server']['user'])) {
return $key . '_' . $cfg['Server']['user'];
}
return $key;
}
public static function has(string $name): bool
{
return isset($_SESSION['cache'][self::key()][$name]);
}
/**
* @return mixed|null
*/
public static function get(string $name, ?callable $defaultValueCallback = null)
{
if (self::has($name)) {
return $_SESSION['cache'][self::key()][$name];
}
if ($defaultValueCallback !== null) {
$value = $defaultValueCallback();
self::set($name, $value);
return $value;
}
return null;
}
/**
* @param mixed $value
*/
public static function set(string $name, $value): void
{
$_SESSION['cache'][self::key()][$name] = $value;
}
public static function remove(string $name): void
{
unset($_SESSION['cache'][self::key()][$name]);
}
}

View File

@ -654,6 +654,13 @@
<code>$a</code>
<code>$b</code>
</MissingClosureParamType>
<NullableReturnStatement occurrences="5">
<code>SessionCache::get('is_amazon_rds')</code>
<code>SessionCache::get('is_createuser')</code>
<code>SessionCache::get('is_grantuser')</code>
<code>SessionCache::get('is_superuser')</code>
<code>SessionCache::get('mysql_cur_user')</code>
</NullableReturnStatement>
<PossiblyInvalidArgument occurrences="1">
<code>$table</code>
</PossiblyInvalidArgument>
@ -1127,8 +1134,9 @@
</MissingConstructor>
</file>
<file src="libraries/classes/Menu.php">
<NullableReturnStatement occurrences="1">
<NullableReturnStatement occurrences="2">
<code>$allowedTabs</code>
<code>SessionCache::get($cache_key)</code>
</NullableReturnStatement>
<PossiblyFalseOperand occurrences="1">
<code>mb_strpos($row['tab'], '_')</code>
@ -2104,6 +2112,11 @@
<code>bool</code>
</InvalidReturnType>
</file>
<file src="libraries/classes/Profiling.php">
<NullableReturnStatement occurrences="1">
<code>SessionCache::get('profiling_supported')</code>
</NullableReturnStatement>
</file>
<file src="libraries/classes/Properties/Options/OptionsPropertyOneItem.php">
<ImplementedReturnTypeMismatch occurrences="1">
<code>bool|string</code>

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\Response;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
class BinlogControllerTest extends AbstractTestCase
{
@ -34,7 +34,7 @@ class BinlogControllerTest extends AbstractTestCase
$GLOBALS['table'] = 'table';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
Util::cacheSet('profiling_supported', true);
SessionCache::set('profiling_supported', true);
}
public function testIndex(): void

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\Server\Status\Monitor;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\Response;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
class MonitorControllerTest extends AbstractTestCase
{
@ -273,7 +273,7 @@ class MonitorControllerTest extends AbstractTestCase
global $cached_affected_rows;
$cached_affected_rows = 'cached_affected_rows';
Util::cacheSet('profiling_supported', true);
SessionCache::set('profiling_supported', true);
$value = [
'sql_text' => 'insert sql_text',

View File

@ -12,7 +12,7 @@ use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\SystemDatabase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
use stdClass;
/**
@ -48,7 +48,7 @@ class DatabaseInterfaceTest extends AbstractTestCase
*/
public function testGetCurrentUser($value, string $string, array $expected): void
{
Util::cacheUnset('mysql_cur_user');
SessionCache::remove('mysql_cur_user');
$extension = new DbiDummy();
/** @var array $value */
@ -290,7 +290,7 @@ class DatabaseInterfaceTest extends AbstractTestCase
*/
public function atestIsAmazonRdsData(array $value, bool $expected): void
{
Util::cacheUnset('is_amazon_rds');
SessionCache::remove('is_amazon_rds');
$extension = new DbiDummy();
$extension->setResult('SELECT @@basedir', $value);

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Profiling;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
class ProfilingTest extends AbstractTestCase
{
@ -15,11 +15,11 @@ class ProfilingTest extends AbstractTestCase
$server = 1;
Util::cacheSet('profiling_supported', true);
SessionCache::set('profiling_supported', true);
$condition = Profiling::isSupported($dbi);
$this->assertTrue($condition);
Util::cacheSet('profiling_supported', false);
SessionCache::set('profiling_supported', false);
$condition = Profiling::isSupported($dbi);
$this->assertFalse($condition);
}

View File

@ -10,6 +10,7 @@ use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\SessionCache;
use const LC_ALL;
use function date_default_timezone_get;
use function date_default_timezone_set;
@ -445,77 +446,6 @@ class UtilTest extends AbstractTestCase
$this->assertEquals(16, strlen(Util::generateRandom(16)));
}
/**
* Test if cached data is available after set
*
* @covers \PhpMyAdmin\Util::cacheExists
*/
public function testCacheExists(): void
{
$GLOBALS['server'] = 'server';
Util::cacheSet('test_data', 5);
Util::cacheSet('test_data_2', 5);
$this->assertTrue(Util::cacheExists('test_data'));
$this->assertTrue(Util::cacheExists('test_data_2'));
$this->assertFalse(Util::cacheExists('fake_data_2'));
}
/**
* Test if PhpMyAdmin\Util::cacheGet does not return data for non existing cache entries
*
* @covers \PhpMyAdmin\Util::cacheGet
*/
public function testCacheGet(): void
{
$GLOBALS['server'] = 'server';
Util::cacheSet('test_data', 5);
Util::cacheSet('test_data_2', 5);
$this->assertNotNull(Util::cacheGet('test_data'));
$this->assertNotNull(Util::cacheGet('test_data_2'));
$this->assertNull(Util::cacheGet('fake_data_2'));
}
/**
* Test retrieval of cached data
*
* @covers \PhpMyAdmin\Util::cacheSet
*/
public function testCacheSetGet(): void
{
$GLOBALS['server'] = 'server';
Util::cacheSet('test_data', 25);
Util::cacheSet('test_data', 5);
$this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
Util::cacheSet('test_data_3', 3);
$this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
}
/**
* Test clearing cached values
*
* @covers \PhpMyAdmin\Util::cacheUnset
*/
public function testCacheUnSet(): void
{
$GLOBALS['server'] = 'server';
Util::cacheSet('test_data', 25);
Util::cacheSet('test_data_2', 25);
Util::cacheUnset('test_data');
$this->assertArrayNotHasKey(
'test_data',
$_SESSION['cache']['server_server']
);
Util::cacheUnset('test_data_2');
$this->assertArrayNotHasKey(
'test_data_2',
$_SESSION['cache']['server_server']
);
}
/**
* Test clearing user cache
*
@ -524,7 +454,7 @@ class UtilTest extends AbstractTestCase
public function testClearUserCache(): void
{
$GLOBALS['server'] = 'server';
Util::cacheSet('is_superuser', 'yes');
SessionCache::set('is_superuser', 'yes');
$this->assertEquals(
'yes',
$_SESSION['cache']['server_server']['is_superuser']

View File

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Utils;
use PhpMyAdmin\Utils\SessionCache;
use PHPUnit\Framework\TestCase;
class SessionCacheTest extends TestCase
{
public function testGet(): void
{
global $server;
$server = 'server';
SessionCache::set('test_data', 5);
SessionCache::set('test_data_2', 5);
$this->assertNotNull(SessionCache::get('test_data'));
$this->assertNotNull(SessionCache::get('test_data_2'));
$this->assertNull(SessionCache::get('fake_data_2'));
}
public function testRemove(): void
{
global $server;
$server = 'server';
SessionCache::set('test_data', 25);
SessionCache::set('test_data_2', 25);
SessionCache::remove('test_data');
$this->assertArrayNotHasKey(
'test_data',
$_SESSION['cache']['server_server']
);
SessionCache::remove('test_data_2');
$this->assertArrayNotHasKey(
'test_data_2',
$_SESSION['cache']['server_server']
);
}
public function testSet(): void
{
global $server;
$server = 'server';
SessionCache::set('test_data', 25);
SessionCache::set('test_data', 5);
$this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
SessionCache::set('test_data_3', 3);
$this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
}
public function testHas(): void
{
global $server;
$server = 'server';
SessionCache::set('test_data', 5);
SessionCache::set('test_data_2', 5);
$this->assertTrue(SessionCache::has('test_data'));
$this->assertTrue(SessionCache::has('test_data_2'));
$this->assertFalse(SessionCache::has('fake_data_2'));
}
}