public function setUp() { $this->config = $this->getMock('Cm\\RedisSession\\Handler\\ConfigInterface', [], [], '', false); $this->config->expects($this->once())->method('getLogLevel')->willReturn(LoggerInterface::DEBUG); $this->psrLogger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false); $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); //$this->logger = new Logger($this->config, $this->psrLogger, $this->request); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->logger = $objectManager->getObject('Magento\\Framework\\Session\\SaveHandler\\Redis\\Logger', ['config' => $this->config, 'logger' => $this->psrLogger, 'request' => $this->request]); }
/** * @param Handler\ConfigInterface $config * @param Handler\LoggerInterface $logger * @param Handler\ProfilerInterface|null $profiler */ public function __construct(\Cm\RedisSession\Handler\ConfigInterface $config, \Cm\RedisSession\Handler\LoggerInterface $logger, \Cm\RedisSession\Handler\ProfilerInterface $profiler = null) { $this->_config = $config; $this->logger = $logger; $this->profiler = $profiler; $this->_logLevel = (int) ($config->descend('log_level') ?: self::DEFAULT_LOG_LEVEL); if ($this->_logLevel >= \Zend_Log::DEBUG) { $timeStart = microtime(true); } // Database config $host = "{$config->descend('host')}" ?: '127.0.0.1'; $port = (int) $config->descend('port') ?: 6379; $pass = (string) ($config->descend('password') ?: ''); $timeout = (double) ($config->descend('timeout') ?: self::DEFAULT_TIMEOUT); $persistent = (string) ($config->descend('persistent') ?: ''); $this->_dbNum = (int) ($config->descend('db') ?: 0); // General config $this->_compressionThreshold = (int) ($config->descend('compression_threshold') ?: self::DEFAULT_COMPRESSION_THRESHOLD); $this->_compressionLib = (string) ($config->descend('compression_lib') ?: self::DEFAULT_COMPRESSION_LIB); $this->_maxConcurrency = (int) ($config->descend('max_concurrency') ?: self::DEFAULT_MAX_CONCURRENCY); $this->_maxLifetime = (int) ($config->descend('max_lifetime') ?: self::DEFAULT_MAX_LIFETIME); $this->_minLifetime = (int) ($config->descend('min_lifetime') ?: self::DEFAULT_MIN_LIFETIME); $this->_useLocking = defined('CM_REDISSESSION_LOCKING_ENABLED') ? CM_REDISSESSION_LOCKING_ENABLED : !(strlen("{$config->descend('disable_locking')}") ? (bool) "{$config->descend('disable_locking')}" : self::DEFAULT_DISABLE_LOCKING); // Use sleep time multiplier so break time is in seconds $this->_failAfter = (int) round(1000000 / self::SLEEP_TIME * self::FAIL_AFTER); // Connect and authenticate $this->_redis = new \Credis_Client($host, $port, $timeout, $persistent); if (!empty($pass)) { $this->_redis->auth($pass) or \Zend_Cache::throwException('Unable to authenticate with the redis server.'); } $this->_redis->setCloseOnDestruct(FALSE); // Destructor order cannot be predicted if ($this->_logLevel >= \Zend_Log::DEBUG) { $this->_log(sprintf("%s initialized for connection to %s:%s after %.5f seconds", get_class($this), $host, $port, microtime(true) - $timeStart)); } }
/** * Logger constructor * * @param ConfigInterface $config * @param LoggerInterface $logger * @param Request $request */ public function __construct(ConfigInterface $config, LoggerInterface $logger, Request $request) { $this->logger = $logger; $this->request = $request; $this->logLevel = $config->getLogLevel() ?: self::ALERT; }
/** * Get break time, calculated later than other config settings due to requiring session name to be set * * @return int */ private function _getBreakAfter() { // Has break after already been calculated? Only fetch from config once, then reuse variable. if (!$this->_breakAfter) { // Fetch relevant setting from config using session name $this->_breakAfter = (double) ($this->config->getBreakAfter() ?: self::DEFAULT_BREAK_AFTER); // Use sleep time multiplier so break time is in seconds $this->_breakAfter = (int) round(1000000 / self::SLEEP_TIME * $this->_breakAfter); } return $this->_breakAfter; }