mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
Merge pull request #414 from top-think/analysis-q5kY3W
Apply fixes from StyleCI
This commit is contained in:
@@ -17,4 +17,4 @@ require __DIR__ . '/base.php';
|
|||||||
|
|
||||||
// 执行应用
|
// 执行应用
|
||||||
App::initCommon();
|
App::initCommon();
|
||||||
Console::init();
|
Console::init();
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class Debug
|
|||||||
$output = '<pre>' . $label . $output . '</pre>';
|
$output = '<pre>' . $label . $output . '</pre>';
|
||||||
}
|
}
|
||||||
if ($echo) {
|
if ($echo) {
|
||||||
echo ($output);
|
echo($output);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return $output;
|
return $output;
|
||||||
|
|||||||
@@ -1,360 +1,360 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\exception\ClassNotFoundException;
|
use think\exception\ClassNotFoundException;
|
||||||
|
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
protected static $prefix = '';
|
protected static $prefix = '';
|
||||||
protected static $init = null;
|
protected static $init = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置或者获取session作用域(前缀)
|
* 设置或者获取session作用域(前缀)
|
||||||
* @param string $prefix
|
* @param string $prefix
|
||||||
* @return string|void
|
* @return string|void
|
||||||
*/
|
*/
|
||||||
public static function prefix($prefix = '')
|
public static function prefix($prefix = '')
|
||||||
{
|
{
|
||||||
if (empty($prefix) && null !== $prefix) {
|
if (empty($prefix) && null !== $prefix) {
|
||||||
return self::$prefix;
|
return self::$prefix;
|
||||||
} else {
|
} else {
|
||||||
self::$prefix = $prefix;
|
self::$prefix = $prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session初始化
|
* session初始化
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
*/
|
*/
|
||||||
public static function init(array $config = [])
|
public static function init(array $config = [])
|
||||||
{
|
{
|
||||||
if (empty($config)) {
|
if (empty($config)) {
|
||||||
$config = Config::get('session');
|
$config = Config::get('session');
|
||||||
}
|
}
|
||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info');
|
App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info');
|
||||||
$isDoStart = false;
|
$isDoStart = false;
|
||||||
if (isset($config['use_trans_sid'])) {
|
if (isset($config['use_trans_sid'])) {
|
||||||
ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0);
|
ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启动session
|
// 启动session
|
||||||
if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) {
|
if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) {
|
||||||
ini_set('session.auto_start', 0);
|
ini_set('session.auto_start', 0);
|
||||||
$isDoStart = true;
|
$isDoStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['prefix'])) {
|
if (isset($config['prefix'])) {
|
||||||
self::$prefix = $config['prefix'];
|
self::$prefix = $config['prefix'];
|
||||||
}
|
}
|
||||||
if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) {
|
if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) {
|
||||||
session_id($_REQUEST[$config['var_session_id']]);
|
session_id($_REQUEST[$config['var_session_id']]);
|
||||||
} elseif (isset($config['id']) && !empty($config['id'])) {
|
} elseif (isset($config['id']) && !empty($config['id'])) {
|
||||||
session_id($config['id']);
|
session_id($config['id']);
|
||||||
}
|
}
|
||||||
if (isset($config['name'])) {
|
if (isset($config['name'])) {
|
||||||
session_name($config['name']);
|
session_name($config['name']);
|
||||||
}
|
}
|
||||||
if (isset($config['path'])) {
|
if (isset($config['path'])) {
|
||||||
session_save_path($config['path']);
|
session_save_path($config['path']);
|
||||||
}
|
}
|
||||||
if (isset($config['domain'])) {
|
if (isset($config['domain'])) {
|
||||||
ini_set('session.cookie_domain', $config['domain']);
|
ini_set('session.cookie_domain', $config['domain']);
|
||||||
}
|
}
|
||||||
if (isset($config['expire'])) {
|
if (isset($config['expire'])) {
|
||||||
ini_set('session.gc_maxlifetime', $config['expire']);
|
ini_set('session.gc_maxlifetime', $config['expire']);
|
||||||
ini_set('session.cookie_lifetime', $config['expire']);
|
ini_set('session.cookie_lifetime', $config['expire']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($config['use_cookies'])) {
|
if (isset($config['use_cookies'])) {
|
||||||
ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
|
ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
|
||||||
}
|
}
|
||||||
if (isset($config['cache_limiter'])) {
|
if (isset($config['cache_limiter'])) {
|
||||||
session_cache_limiter($config['cache_limiter']);
|
session_cache_limiter($config['cache_limiter']);
|
||||||
}
|
}
|
||||||
if (isset($config['cache_expire'])) {
|
if (isset($config['cache_expire'])) {
|
||||||
session_cache_expire($config['cache_expire']);
|
session_cache_expire($config['cache_expire']);
|
||||||
}
|
}
|
||||||
if (!empty($config['type'])) {
|
if (!empty($config['type'])) {
|
||||||
// 读取session驱动
|
// 读取session驱动
|
||||||
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
|
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
|
||||||
|
|
||||||
// 检查驱动类
|
// 检查驱动类
|
||||||
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
|
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
|
||||||
throw new ClassNotFoundException('error session handler:' . $class, $class);
|
throw new ClassNotFoundException('error session handler:' . $class, $class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($isDoStart) {
|
if ($isDoStart) {
|
||||||
session_start();
|
session_start();
|
||||||
self::$init = true;
|
self::$init = true;
|
||||||
} else {
|
} else {
|
||||||
self::$init = false;
|
self::$init = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session自动启动或者初始化
|
* session自动启动或者初始化
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function boot()
|
public static function boot()
|
||||||
{
|
{
|
||||||
if (is_null(self::$init)) {
|
if (is_null(self::$init)) {
|
||||||
self::init();
|
self::init();
|
||||||
} elseif (false === self::$init) {
|
} elseif (false === self::$init) {
|
||||||
if (PHP_SESSION_ACTIVE != session_status()) {
|
if (PHP_SESSION_ACTIVE != session_status()) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
self::$init = true;
|
self::$init = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session设置
|
* session设置
|
||||||
* @param string $name session名称
|
* @param string $name session名称
|
||||||
* @param mixed $value session值
|
* @param mixed $value session值
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set($name, $value = '', $prefix = null)
|
public static function set($name, $value = '', $prefix = null)
|
||||||
{
|
{
|
||||||
empty(self::$init) && self::boot();
|
empty(self::$init) && self::boot();
|
||||||
|
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
// 二维数组赋值
|
// 二维数组赋值
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
$_SESSION[$prefix][$name1][$name2] = $value;
|
$_SESSION[$prefix][$name1][$name2] = $value;
|
||||||
} else {
|
} else {
|
||||||
$_SESSION[$name1][$name2] = $value;
|
$_SESSION[$name1][$name2] = $value;
|
||||||
}
|
}
|
||||||
} elseif ($prefix) {
|
} elseif ($prefix) {
|
||||||
$_SESSION[$prefix][$name] = $value;
|
$_SESSION[$prefix][$name] = $value;
|
||||||
} else {
|
} else {
|
||||||
$_SESSION[$name] = $value;
|
$_SESSION[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session获取
|
* session获取
|
||||||
* @param string $name session名称
|
* @param string $name session名称
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function get($name = '', $prefix = null)
|
public static function get($name = '', $prefix = null)
|
||||||
{
|
{
|
||||||
empty(self::$init) && self::boot();
|
empty(self::$init) && self::boot();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if ('' == $name) {
|
if ('' == $name) {
|
||||||
// 获取全部的session
|
// 获取全部的session
|
||||||
$value = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION;
|
$value = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION;
|
||||||
} elseif ($prefix) {
|
} elseif ($prefix) {
|
||||||
// 获取session
|
// 获取session
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
$value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null;
|
$value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null;
|
||||||
} else {
|
} else {
|
||||||
$value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null;
|
$value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
$value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null;
|
$value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null;
|
||||||
} else {
|
} else {
|
||||||
$value = isset($_SESSION[$name]) ? $_SESSION[$name] : null;
|
$value = isset($_SESSION[$name]) ? $_SESSION[$name] : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session获取并删除
|
* session获取并删除
|
||||||
* @param string $name session名称
|
* @param string $name session名称
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function pull($name, $prefix = null)
|
public static function pull($name, $prefix = null)
|
||||||
{
|
{
|
||||||
$result = self::get($name, $prefix);
|
$result = self::get($name, $prefix);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
self::delete($name, $prefix);
|
self::delete($name, $prefix);
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session设置 下一次请求有效
|
* session设置 下一次请求有效
|
||||||
* @param string $name session名称
|
* @param string $name session名称
|
||||||
* @param mixed $value session值
|
* @param mixed $value session值
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function flash($name, $value)
|
public static function flash($name, $value)
|
||||||
{
|
{
|
||||||
self::set($name, $value);
|
self::set($name, $value);
|
||||||
if (!self::has('__flash__.__time__')) {
|
if (!self::has('__flash__.__time__')) {
|
||||||
self::set('__flash__.__time__', $_SERVER['REQUEST_TIME_FLOAT']);
|
self::set('__flash__.__time__', $_SERVER['REQUEST_TIME_FLOAT']);
|
||||||
}
|
}
|
||||||
self::push('__flash__', $name);
|
self::push('__flash__', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空当前请求的session数据
|
* 清空当前请求的session数据
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function flush()
|
public static function flush()
|
||||||
{
|
{
|
||||||
if (self::$init) {
|
if (self::$init) {
|
||||||
$item = self::get('__flash__');
|
$item = self::get('__flash__');
|
||||||
|
|
||||||
if (!empty($item)) {
|
if (!empty($item)) {
|
||||||
$time = $item['__time__'];
|
$time = $item['__time__'];
|
||||||
if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) {
|
if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) {
|
||||||
unset($item['__time__']);
|
unset($item['__time__']);
|
||||||
self::delete($item);
|
self::delete($item);
|
||||||
self::set('__flash__', []);
|
self::set('__flash__', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除session数据
|
* 删除session数据
|
||||||
* @param string|array $name session名称
|
* @param string|array $name session名称
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function delete($name, $prefix = null)
|
public static function delete($name, $prefix = null)
|
||||||
{
|
{
|
||||||
empty(self::$init) && self::boot();
|
empty(self::$init) && self::boot();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
foreach ($name as $key) {
|
foreach ($name as $key) {
|
||||||
self::delete($key, $prefix);
|
self::delete($key, $prefix);
|
||||||
}
|
}
|
||||||
} elseif (strpos($name, '.')) {
|
} elseif (strpos($name, '.')) {
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
unset($_SESSION[$prefix][$name1][$name2]);
|
unset($_SESSION[$prefix][$name1][$name2]);
|
||||||
} else {
|
} else {
|
||||||
unset($_SESSION[$name1][$name2]);
|
unset($_SESSION[$name1][$name2]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
unset($_SESSION[$prefix][$name]);
|
unset($_SESSION[$prefix][$name]);
|
||||||
} else {
|
} else {
|
||||||
unset($_SESSION[$name]);
|
unset($_SESSION[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空session数据
|
* 清空session数据
|
||||||
* @param string|null $prefix 作用域(前缀)
|
* @param string|null $prefix 作用域(前缀)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function clear($prefix = null)
|
public static function clear($prefix = null)
|
||||||
{
|
{
|
||||||
empty(self::$init) && self::boot();
|
empty(self::$init) && self::boot();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
unset($_SESSION[$prefix]);
|
unset($_SESSION[$prefix]);
|
||||||
} else {
|
} else {
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断session数据
|
* 判断session数据
|
||||||
* @param string $name session名称
|
* @param string $name session名称
|
||||||
* @param string|null $prefix
|
* @param string|null $prefix
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has($name, $prefix = null)
|
public static function has($name, $prefix = null)
|
||||||
{
|
{
|
||||||
empty(self::$init) && self::boot();
|
empty(self::$init) && self::boot();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
// 支持数组
|
// 支持数组
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]);
|
return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]);
|
||||||
} else {
|
} else {
|
||||||
return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]);
|
return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加数据到一个session数组
|
* 添加数据到一个session数组
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function push($key, $value)
|
public static function push($key, $value)
|
||||||
{
|
{
|
||||||
$array = self::get($key);
|
$array = self::get($key);
|
||||||
if (is_null($array)) {
|
if (is_null($array)) {
|
||||||
$array = [];
|
$array = [];
|
||||||
}
|
}
|
||||||
$array[] = $value;
|
$array[] = $value;
|
||||||
self::set($key, $array);
|
self::set($key, $array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动session
|
* 启动session
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function start()
|
public static function start()
|
||||||
{
|
{
|
||||||
session_start();
|
session_start();
|
||||||
self::$init = true;
|
self::$init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 销毁session
|
* 销毁session
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function destroy()
|
public static function destroy()
|
||||||
{
|
{
|
||||||
if (!empty($_SESSION)) {
|
if (!empty($_SESSION)) {
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
}
|
}
|
||||||
session_unset();
|
session_unset();
|
||||||
session_destroy();
|
session_destroy();
|
||||||
self::$init = null;
|
self::$init = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重新生成session_id
|
* 重新生成session_id
|
||||||
* @param bool $delete 是否删除关联会话文件
|
* @param bool $delete 是否删除关联会话文件
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function regenerate($delete = false)
|
private static function regenerate($delete = false)
|
||||||
{
|
{
|
||||||
session_regenerate_id($delete);
|
session_regenerate_id($delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停session
|
* 暂停session
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function pause()
|
public static function pause()
|
||||||
{
|
{
|
||||||
// 暂停session
|
// 暂停session
|
||||||
session_write_close();
|
session_write_close();
|
||||||
self::$init = false;
|
self::$init = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ class Url
|
|||||||
$domain .= $rootDomain;
|
$domain .= $rootDomain;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (false !== strpos($key, '*')) {
|
} elseif (false !== strpos($key, '*')) {
|
||||||
if (!empty($rootDomain)) {
|
if (!empty($rootDomain)) {
|
||||||
$domain .= $rootDomain;
|
$domain .= $rootDomain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,4 +71,4 @@ EOF
|
|||||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
|
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,4 +278,4 @@ EOF;
|
|||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,4 +337,4 @@ class Ask
|
|||||||
|
|
||||||
return self::$stty = $exitcode === 0;
|
return self::$stty = $exitcode === 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,4 +71,4 @@ class Collection extends \think\Collection
|
|||||||
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ class Bootstrap extends Paginator
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染分页html
|
* 渲染分页html
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -127,7 +126,6 @@ class Bootstrap extends Paginator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成一个可点击的按钮
|
* 生成一个可点击的按钮
|
||||||
*
|
*
|
||||||
@@ -204,4 +202,4 @@ class Bootstrap extends Paginator
|
|||||||
|
|
||||||
return $this->getAvailablePageWrapper($url, $page);
|
return $this->getAvailablePageWrapper($url, $page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,4 +58,4 @@ class Timeout extends \RuntimeException
|
|||||||
throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
|
throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ abstract class Pipes
|
|||||||
*/
|
*/
|
||||||
abstract public function areOpen();
|
abstract public function areOpen();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -91,4 +90,4 @@ abstract class Pipes
|
|||||||
|
|
||||||
$this->blocked = false;
|
$this->blocked = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
// 测试入口文件
|
// 测试入口文件
|
||||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
// 定义项目测试基础路径
|
// 定义项目测试基础路径
|
||||||
define('TEST_PATH', __DIR__ . '/');
|
define('TEST_PATH', __DIR__ . '/');
|
||||||
// 定义项目路径
|
// 定义项目路径
|
||||||
define('APP_PATH', __DIR__ . '/application/');
|
define('APP_PATH', __DIR__ . '/application/');
|
||||||
// 加载框架基础文件
|
// 加载框架基础文件
|
||||||
require __DIR__ . '/../base.php';
|
require __DIR__ . '/../base.php';
|
||||||
\think\Loader::addNamespace('tests', TEST_PATH);
|
\think\Loader::addNamespace('tests', TEST_PATH);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use ReflectionClass;
|
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ namespace tests\thinkphp\library\think\behavior;
|
|||||||
|
|
||||||
class One
|
class One
|
||||||
{
|
{
|
||||||
public function run(&$data){
|
public function run(&$data) {
|
||||||
$data['id'] = 1;
|
$data['id'] = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(&$data){
|
public function test(&$data) {
|
||||||
$data['name'] = 'test';
|
$data['name'] = 'test';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ namespace tests\thinkphp\library\think\behavior;
|
|||||||
|
|
||||||
class Three
|
class Three
|
||||||
{
|
{
|
||||||
public function run(&$data){
|
public function run(&$data) {
|
||||||
$data['id'] = 3;
|
$data['id'] = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ namespace tests\thinkphp\library\think\behavior;
|
|||||||
|
|
||||||
class Two
|
class Two
|
||||||
{
|
{
|
||||||
public function run(&$data){
|
public function run(&$data) {
|
||||||
$data['id'] = 2;
|
$data['id'] = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,207 +1,207 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存抽象类,提供一些测试
|
* 缓存抽象类,提供一些测试
|
||||||
* @author simon <mahuan@d1web.top>
|
* @author simon <mahuan@d1web.top>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
|
|
||||||
abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存句柄,子类必须有
|
* 获取缓存句柄,子类必须有
|
||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
abstract protected function getCacheInstance();
|
abstract protected function getCacheInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tearDown函数
|
* tearDown函数
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定一组测试值,包括测试字符串、整数、数组和对象
|
* 设定一组测试值,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function prepare()
|
public function prepare()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$cache->clear();
|
$cache->clear();
|
||||||
$cache->set('string_test', 'string_test');
|
$cache->set('string_test', 'string_test');
|
||||||
$cache->set('number_test', 11);
|
$cache->set('number_test', 11);
|
||||||
$cache->set('array_test', ['array_test' => 'array_test']);
|
$cache->set('array_test', ['array_test' => 'array_test']);
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存设置,包括测试字符串、整数、数组和对象
|
* 测试缓存设置,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testSet()
|
public function testSet()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertTrue($cache->set('string_test', 'string_test'));
|
$this->assertTrue($cache->set('string_test', 'string_test'));
|
||||||
$this->assertTrue($cache->set('number_test', 11));
|
$this->assertTrue($cache->set('number_test', 11));
|
||||||
$this->assertTrue($cache->set('array_test', ['array_test' => 'array_test']));
|
$this->assertTrue($cache->set('array_test', ['array_test' => 'array_test']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存自增
|
* 测试缓存自增
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testInc()
|
public function testInc()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertEquals(14, $cache->inc('number_test', 3));
|
$this->assertEquals(14, $cache->inc('number_test', 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存自减
|
* 测试缓存自减
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testDec()
|
public function testDec()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertEquals(8, $cache->dec('number_test', 6));
|
$this->assertEquals(8, $cache->dec('number_test', 6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存读取,包括测试字符串、整数、数组和对象
|
* 测试缓存读取,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
$cache = $this->prepare();
|
$cache = $this->prepare();
|
||||||
$this->assertEquals('string_test', $cache->get('string_test'));
|
$this->assertEquals('string_test', $cache->get('string_test'));
|
||||||
$this->assertEquals(11, $cache->get('number_test'));
|
$this->assertEquals(11, $cache->get('number_test'));
|
||||||
$array = $cache->get('array_test');
|
$array = $cache->get('array_test');
|
||||||
$this->assertArrayHasKey('array_test', $array);
|
$this->assertArrayHasKey('array_test', $array);
|
||||||
$this->assertEquals('array_test', $array['array_test']);
|
$this->assertEquals('array_test', $array['array_test']);
|
||||||
|
|
||||||
$result = $cache->set('no_expire', 1, 0);
|
$result = $cache->set('no_expire', 1, 0);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存存在情况,包括测试字符串、整数、数组和对象
|
* 测试缓存存在情况,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testExists()
|
public function testExists()
|
||||||
{
|
{
|
||||||
$cache = $this->prepare();
|
$cache = $this->prepare();
|
||||||
$this->assertNotEmpty($cache->has('string_test'));
|
$this->assertNotEmpty($cache->has('string_test'));
|
||||||
$this->assertNotEmpty($cache->has('number_test'));
|
$this->assertNotEmpty($cache->has('number_test'));
|
||||||
$this->assertFalse($cache->has('not_exists'));
|
$this->assertFalse($cache->has('not_exists'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存不存在情况,包括测试字符串、整数、数组和对象
|
* 测试缓存不存在情况,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testGetNonExistent()
|
public function testGetNonExistent()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertFalse($cache->get('non_existent_key', false));
|
$this->assertFalse($cache->get('non_existent_key', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试特殊值缓存,包括测试字符串、整数、数组和对象
|
* 测试特殊值缓存,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testStoreSpecialValues()
|
public function testStoreSpecialValues()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$cache->set('null_value', null);
|
$cache->set('null_value', null);
|
||||||
//清空缓存后,返回null而不是false
|
//清空缓存后,返回null而不是false
|
||||||
$this->assertTrue(is_null($cache->get('null_value')));
|
$this->assertTrue(is_null($cache->get('null_value')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存过期测试
|
* 缓存过期测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testExpire()
|
public function testExpire()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertTrue($cache->set('expire_test', 'expire_test', 1));
|
$this->assertTrue($cache->set('expire_test', 'expire_test', 1));
|
||||||
usleep(600000);
|
usleep(600000);
|
||||||
$this->assertEquals('expire_test', $cache->get('expire_test'));
|
$this->assertEquals('expire_test', $cache->get('expire_test'));
|
||||||
usleep(800000);
|
usleep(800000);
|
||||||
$this->assertFalse($cache->get('expire_test'));
|
$this->assertFalse($cache->get('expire_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除缓存测试
|
* 删除缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$cache = $this->prepare();
|
$cache = $this->prepare();
|
||||||
$this->assertNotNull($cache->rm('number_test'));
|
$this->assertNotNull($cache->rm('number_test'));
|
||||||
$this->assertFalse($cache->get('number_test'));
|
$this->assertFalse($cache->get('number_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取并删除缓存测试
|
* 获取并删除缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testPull()
|
public function testPull()
|
||||||
{
|
{
|
||||||
$cache = $this->prepare();
|
$cache = $this->prepare();
|
||||||
$this->assertEquals(11, $cache->pull('number_test'));
|
$this->assertEquals(11, $cache->pull('number_test'));
|
||||||
$this->assertFalse($cache->get('number_test'));
|
$this->assertFalse($cache->get('number_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空缓存测试
|
* 清空缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testClear()
|
public function testClear()
|
||||||
{
|
{
|
||||||
$cache = $this->prepare();
|
$cache = $this->prepare();
|
||||||
$this->assertTrue($cache->clear());
|
$this->assertTrue($cache->clear());
|
||||||
$this->assertFalse($cache->get('number_test'));
|
$this->assertFalse($cache->get('number_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStaticCall()
|
public function testStaticCall()
|
||||||
{
|
{
|
||||||
$this->assertTrue(Cache::set('a', 1));
|
$this->assertTrue(Cache::set('a', 1));
|
||||||
$this->assertEquals(1, Cache::get('a'));
|
$this->assertEquals(1, Cache::get('a'));
|
||||||
$this->assertEquals(2, Cache::inc('a'));
|
$this->assertEquals(2, Cache::inc('a'));
|
||||||
$this->assertEquals(4, Cache::inc('a', 2));
|
$this->assertEquals(4, Cache::inc('a', 2));
|
||||||
$this->assertEquals(4, Cache::get('a'));
|
$this->assertEquals(4, Cache::get('a'));
|
||||||
$this->assertEquals(3, Cache::dec('a'));
|
$this->assertEquals(3, Cache::dec('a'));
|
||||||
$this->assertEquals(1, Cache::dec('a', 2));
|
$this->assertEquals(1, Cache::dec('a', 2));
|
||||||
$this->assertEquals(1, Cache::get('a'));
|
$this->assertEquals(1, Cache::get('a'));
|
||||||
$this->assertNotNull(Cache::rm('a'));
|
$this->assertNotNull(Cache::rm('a'));
|
||||||
$this->assertNotNull(Cache::clear());
|
$this->assertNotNull(Cache::clear());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File缓存驱动测试
|
* File缓存驱动测试
|
||||||
* @author 刘志淳 <chun@engineer.com>
|
* @author 刘志淳 <chun@engineer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
class fileTest extends cacheTestCase
|
class fileTest extends cacheTestCase
|
||||||
{
|
{
|
||||||
private $_cacheInstance = null;
|
private $_cacheInstance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基境缓存类型
|
* 基境缓存类型
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
\think\Cache::connect(['type' => 'File', 'path' => CACHE_PATH]);
|
\think\Cache::connect(['type' => 'File', 'path' => CACHE_PATH]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FileCache
|
* @return FileCache
|
||||||
*/
|
*/
|
||||||
protected function getCacheInstance()
|
protected function getCacheInstance()
|
||||||
{
|
{
|
||||||
if (null === $this->_cacheInstance) {
|
if (null === $this->_cacheInstance) {
|
||||||
$this->_cacheInstance = new \think\cache\driver\File();
|
$this->_cacheInstance = new \think\cache\driver\File();
|
||||||
}
|
}
|
||||||
return $this->_cacheInstance;
|
return $this->_cacheInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip testExpire
|
// skip testExpire
|
||||||
public function testExpire()
|
public function testExpire()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,69 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lite缓存驱动测试
|
* Lite缓存驱动测试
|
||||||
* @author 刘志淳 <chun@engineer.com>
|
* @author 刘志淳 <chun@engineer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
|
|
||||||
class liteTest extends \PHPUnit_Framework_TestCase
|
class liteTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function getCacheInstance()
|
protected function getCacheInstance()
|
||||||
{
|
{
|
||||||
return Cache::connect(['type' => 'Lite', 'path' => CACHE_PATH]);
|
return Cache::connect(['type' => 'Lite', 'path' => CACHE_PATH]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存读取
|
* 测试缓存读取
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertFalse($cache->get('test'));
|
$this->assertFalse($cache->get('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存设置
|
* 测试缓存设置
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testSet()
|
public function testSet()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertNotEmpty($cache->set('test', 'test'));
|
$this->assertNotEmpty($cache->set('test', 'test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除缓存测试
|
* 删除缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testRm()
|
public function testRm()
|
||||||
{
|
{
|
||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertTrue($cache->rm('test'));
|
$this->assertTrue($cache->rm('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空缓存测试
|
* 清空缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testClear()
|
public function testClear()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,49 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memcache缓存驱动测试
|
* Memcache缓存驱动测试
|
||||||
* @author 刘志淳 <chun@engineer.com>
|
* @author 刘志淳 <chun@engineer.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
class memcacheTest extends cacheTestCase
|
class memcacheTest extends cacheTestCase
|
||||||
{
|
{
|
||||||
private $_cacheInstance = null;
|
private $_cacheInstance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基境缓存类型
|
* 基境缓存类型
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
if (!extension_loaded('memcache')) {
|
if (!extension_loaded('memcache')) {
|
||||||
$this->markTestSkipped("Memcache没有安装,已跳过测试!");
|
$this->markTestSkipped("Memcache没有安装,已跳过测试!");
|
||||||
}
|
}
|
||||||
\think\Cache::connect(['type' => 'memcache', 'expire' => 2]);
|
\think\Cache::connect(['type' => 'memcache', 'expire' => 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ApcCache
|
* @return ApcCache
|
||||||
*/
|
*/
|
||||||
protected function getCacheInstance()
|
protected function getCacheInstance()
|
||||||
{
|
{
|
||||||
if (null === $this->_cacheInstance) {
|
if (null === $this->_cacheInstance) {
|
||||||
$this->_cacheInstance = new \think\cache\driver\Memcache(['length' => 3]);
|
$this->_cacheInstance = new \think\cache\driver\Memcache(['length' => 3]);
|
||||||
}
|
}
|
||||||
return $this->_cacheInstance;
|
return $this->_cacheInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip testExpire
|
// skip testExpire
|
||||||
public function testExpire()
|
public function testExpire()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +1,72 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memcached缓存驱动测试
|
* Memcached缓存驱动测试
|
||||||
* @author 7IN0SAN9 <me@7in0.me>
|
* @author 7IN0SAN9 <me@7in0.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
class memcachedTest extends cacheTestCase
|
class memcachedTest extends cacheTestCase
|
||||||
{
|
{
|
||||||
private $_cacheInstance = null;
|
private $_cacheInstance = null;
|
||||||
/**
|
/**
|
||||||
* 基境缓存类型
|
* 基境缓存类型
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
if (!extension_loaded("memcached") && !extension_loaded('memcache')) {
|
if (!extension_loaded("memcached") && !extension_loaded('memcache')) {
|
||||||
$this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!");
|
$this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!");
|
||||||
}
|
}
|
||||||
\think\Cache::connect(array('type' => 'memcached', 'expire' => 2));
|
\think\Cache::connect(array('type' => 'memcached', 'expire' => 2));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return ApcCache
|
* @return ApcCache
|
||||||
*/
|
*/
|
||||||
protected function getCacheInstance()
|
protected function getCacheInstance()
|
||||||
{
|
{
|
||||||
if (null === $this->_cacheInstance) {
|
if (null === $this->_cacheInstance) {
|
||||||
$this->_cacheInstance = new \think\cache\driver\Memcached(['length' => 3]);
|
$this->_cacheInstance = new \think\cache\driver\Memcached(['length' => 3]);
|
||||||
}
|
}
|
||||||
return $this->_cacheInstance;
|
return $this->_cacheInstance;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》
|
* 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testExpire()
|
public function testExpire()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStaticCall()
|
public function testStaticCall()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存自增
|
* 测试缓存自增
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testInc()
|
public function testInc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存自减
|
* 测试缓存自减
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testDec()
|
public function testDec()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ class Foo extends Controller
|
|||||||
|
|
||||||
public function fetchTest()
|
public function fetchTest()
|
||||||
{
|
{
|
||||||
$template = dirname(__FILE__) . '/display.html';
|
$template = dirname(__FILE__) . '/display.html';
|
||||||
return $this->fetch($template, ['name' => 'ThinkPHP']);
|
return $this->fetch($template, ['name' => 'ThinkPHP']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayTest()
|
public function displayTest()
|
||||||
{
|
{
|
||||||
$template = dirname(__FILE__) . '/display.html';
|
$template = dirname(__FILE__) . '/display.html';
|
||||||
return $this->display($template, ['name' => 'ThinkPHP']);
|
return $this->display($template, ['name' => 'ThinkPHP']);
|
||||||
}
|
}
|
||||||
public function test()
|
public function test()
|
||||||
@@ -71,7 +71,7 @@ class Foo extends Controller
|
|||||||
['sex', 'in:0,1', '性别只能为为男或女'],
|
['sex', 'in:0,1', '性别只能为为男或女'],
|
||||||
['age', 'between:1,80', '年龄只能在10-80之间'],
|
['age', 'between:1,80', '年龄只能在10-80之间'],
|
||||||
];
|
];
|
||||||
return $this->validate($data, $validate);
|
return $this->validate($data, $validate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use \think\Db;
|
use think\Db;
|
||||||
|
|
||||||
class dbTest extends \PHPUnit_Framework_TestCase
|
class dbTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -349,5 +349,4 @@ EOF;
|
|||||||
$this->assertNotEquals($cache, $updateCache);
|
$this->assertNotEquals($cache, $updateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,179 +1,179 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug测试
|
* Debug测试
|
||||||
* @author 大漠 <zhylninc@gmail.com>
|
* @author 大漠 <zhylninc@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
|
|
||||||
class debugTest extends \PHPUnit_Framework_TestCase
|
class debugTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var Debug
|
* @var Debug
|
||||||
*/
|
*/
|
||||||
protected $object;
|
protected $object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
* This method is called before a test is executed.
|
* This method is called before a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->object = new Debug();
|
$this->object = new Debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the fixture, for example, closes a network connection.
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
* This method is called after a test is executed.
|
* This method is called after a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::remark
|
* @covers think\Debug::remark
|
||||||
* @todo Implement testRemark().
|
* @todo Implement testRemark().
|
||||||
*/
|
*/
|
||||||
public function testRemark()
|
public function testRemark()
|
||||||
{
|
{
|
||||||
$name = "testremarkkey";
|
$name = "testremarkkey";
|
||||||
Debug::remark($name);
|
Debug::remark($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getRangeTime
|
* @covers think\Debug::getRangeTime
|
||||||
* @todo Implement testGetRangeTime().
|
* @todo Implement testGetRangeTime().
|
||||||
*/
|
*/
|
||||||
public function testGetRangeTime()
|
public function testGetRangeTime()
|
||||||
{
|
{
|
||||||
$start = "testGetRangeTimeStart";
|
$start = "testGetRangeTimeStart";
|
||||||
$end = "testGetRangeTimeEnd";
|
$end = "testGetRangeTimeEnd";
|
||||||
Debug::remark($start);
|
Debug::remark($start);
|
||||||
usleep(20000);
|
usleep(20000);
|
||||||
// \think\Debug::remark($end);
|
// \think\Debug::remark($end);
|
||||||
|
|
||||||
$time = Debug::getRangeTime($start, $end);
|
$time = Debug::getRangeTime($start, $end);
|
||||||
$this->assertLessThan(0.03, $time);
|
$this->assertLessThan(0.03, $time);
|
||||||
//$this->assertEquals(0.03, ceil($time));
|
//$this->assertEquals(0.03, ceil($time));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getUseTime
|
* @covers think\Debug::getUseTime
|
||||||
* @todo Implement testGetUseTime().
|
* @todo Implement testGetUseTime().
|
||||||
*/
|
*/
|
||||||
public function testGetUseTime()
|
public function testGetUseTime()
|
||||||
{
|
{
|
||||||
$time = Debug::getUseTime();
|
$time = Debug::getUseTime();
|
||||||
$this->assertLessThan(20, $time);
|
$this->assertLessThan(20, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getThroughputRate
|
* @covers think\Debug::getThroughputRate
|
||||||
* @todo Implement testGetThroughputRate().
|
* @todo Implement testGetThroughputRate().
|
||||||
*/
|
*/
|
||||||
public function testGetThroughputRate()
|
public function testGetThroughputRate()
|
||||||
{
|
{
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
$throughputRate = Debug::getThroughputRate();
|
$throughputRate = Debug::getThroughputRate();
|
||||||
$this->assertLessThan(10, $throughputRate);
|
$this->assertLessThan(10, $throughputRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getRangeMem
|
* @covers think\Debug::getRangeMem
|
||||||
* @todo Implement testGetRangeMem().
|
* @todo Implement testGetRangeMem().
|
||||||
*/
|
*/
|
||||||
public function testGetRangeMem()
|
public function testGetRangeMem()
|
||||||
{
|
{
|
||||||
$start = "testGetRangeMemStart";
|
$start = "testGetRangeMemStart";
|
||||||
$end = "testGetRangeMemEnd";
|
$end = "testGetRangeMemEnd";
|
||||||
Debug::remark($start);
|
Debug::remark($start);
|
||||||
$str = "";
|
$str = "";
|
||||||
for ($i = 0; $i < 10000; $i++) {
|
for ($i = 0; $i < 10000; $i++) {
|
||||||
$str .= "mem";
|
$str .= "mem";
|
||||||
}
|
}
|
||||||
|
|
||||||
$rangeMem = Debug::getRangeMem($start, $end);
|
$rangeMem = Debug::getRangeMem($start, $end);
|
||||||
|
|
||||||
$this->assertLessThan(33, explode(" ", $rangeMem)[0]);
|
$this->assertLessThan(33, explode(" ", $rangeMem)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getUseMem
|
* @covers think\Debug::getUseMem
|
||||||
* @todo Implement testGetUseMem().
|
* @todo Implement testGetUseMem().
|
||||||
*/
|
*/
|
||||||
public function testGetUseMem()
|
public function testGetUseMem()
|
||||||
{
|
{
|
||||||
$useMem = Debug::getUseMem();
|
$useMem = Debug::getUseMem();
|
||||||
|
|
||||||
$this->assertLessThan(30, explode(" ", $useMem)[0]);
|
$this->assertLessThan(30, explode(" ", $useMem)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getMemPeak
|
* @covers think\Debug::getMemPeak
|
||||||
* @todo Implement testGetMemPeak().
|
* @todo Implement testGetMemPeak().
|
||||||
*/
|
*/
|
||||||
public function testGetMemPeak()
|
public function testGetMemPeak()
|
||||||
{
|
{
|
||||||
$start = "testGetMemPeakStart";
|
$start = "testGetMemPeakStart";
|
||||||
$end = "testGetMemPeakEnd";
|
$end = "testGetMemPeakEnd";
|
||||||
Debug::remark($start);
|
Debug::remark($start);
|
||||||
$str = "";
|
$str = "";
|
||||||
for ($i = 0; $i < 100000; $i++) {
|
for ($i = 0; $i < 100000; $i++) {
|
||||||
$str .= "mem";
|
$str .= "mem";
|
||||||
}
|
}
|
||||||
$memPeak = Debug::getMemPeak($start, $end);
|
$memPeak = Debug::getMemPeak($start, $end);
|
||||||
$this->assertLessThan(500, explode(" ", $memPeak)[0]);
|
$this->assertLessThan(500, explode(" ", $memPeak)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::getFile
|
* @covers think\Debug::getFile
|
||||||
* @todo Implement testGetFile().
|
* @todo Implement testGetFile().
|
||||||
*/
|
*/
|
||||||
public function testGetFile()
|
public function testGetFile()
|
||||||
{
|
{
|
||||||
$count = Debug::getFile();
|
$count = Debug::getFile();
|
||||||
|
|
||||||
$this->assertEquals(count(get_included_files()), $count);
|
$this->assertEquals(count(get_included_files()), $count);
|
||||||
|
|
||||||
$info = Debug::getFile(true);
|
$info = Debug::getFile(true);
|
||||||
$this->assertEquals(count(get_included_files()), count($info));
|
$this->assertEquals(count(get_included_files()), count($info));
|
||||||
|
|
||||||
$this->assertContains("KB", $info[0]);
|
$this->assertContains("KB", $info[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Debug::dump
|
* @covers think\Debug::dump
|
||||||
* @todo Implement testDump().
|
* @todo Implement testDump().
|
||||||
*/
|
*/
|
||||||
public function testDump()
|
public function testDump()
|
||||||
{
|
{
|
||||||
if (strstr(PHP_VERSION, 'hhvm')) {
|
if (strstr(PHP_VERSION, 'hhvm')) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
$var = [];
|
$var = [];
|
||||||
$var["key"] = "val";
|
$var["key"] = "val";
|
||||||
$output = Debug::dump($var, false, $label = "label");
|
$output = Debug::dump($var, false, $label = "label");
|
||||||
$array = explode("array", json_encode($output));
|
$array = explode("array", json_encode($output));
|
||||||
if (IS_WIN) {
|
if (IS_WIN) {
|
||||||
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array));
|
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array));
|
||||||
} else if (strstr(PHP_OS, 'Darwin')) {
|
} elseif (strstr(PHP_OS, 'Darwin')) {
|
||||||
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
|
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
|
$this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'load'=>'加载',
|
'load'=>'加载',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test File Log
|
* Test File Log
|
||||||
*/
|
*/
|
||||||
namespace tests\thinkphp\library\think\log\driver;
|
namespace tests\thinkphp\library\think\log\driver;
|
||||||
|
|
||||||
use think\Log;
|
use think\Log;
|
||||||
|
|
||||||
class fileTest extends \PHPUnit_Framework_TestCase
|
class fileTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
Log::init(['type' => 'file']);
|
Log::init(['type' => 'file']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecord()
|
public function testRecord()
|
||||||
{
|
{
|
||||||
$record_msg = 'record';
|
$record_msg = 'record';
|
||||||
Log::record($record_msg, 'notice');
|
Log::record($record_msg, 'notice');
|
||||||
$logs = Log::getLog();
|
$logs = Log::getLog();
|
||||||
|
|
||||||
$this->assertNotFalse(array_search($record_msg, $logs['notice']));
|
$this->assertNotFalse(array_search($record_msg, $logs['notice']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
|
|
||||||
use think\paginator\driver\Bootstrap;
|
use think\paginator\driver\Bootstrap;
|
||||||
|
|
||||||
class paginateTest extends \PHPUnit_Framework_TestCase
|
class paginateTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -38,7 +37,4 @@ class paginateTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($render, $p->render());
|
$this->assertEquals($render, $p->render());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,95 +1,95 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response测试
|
* Response测试
|
||||||
* @author 大漠 <zhylninc@gmail.com>
|
* @author 大漠 <zhylninc@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
use think\Response;
|
use think\Response;
|
||||||
|
|
||||||
class responseTest extends \PHPUnit_Framework_TestCase
|
class responseTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \think\Response
|
* @var \think\Response
|
||||||
*/
|
*/
|
||||||
protected $object;
|
protected $object;
|
||||||
|
|
||||||
protected $default_return_type;
|
protected $default_return_type;
|
||||||
|
|
||||||
protected $default_ajax_return;
|
protected $default_ajax_return;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
* This method is called before a test is executed.
|
* This method is called before a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// 1.
|
// 1.
|
||||||
// restore_error_handler();
|
// restore_error_handler();
|
||||||
// Warning: Cannot modify header information - headers already sent by (output started at PHPUnit\Util\Printer.php:173)
|
// Warning: Cannot modify header information - headers already sent by (output started at PHPUnit\Util\Printer.php:173)
|
||||||
// more see in https://www.analysisandsolutions.com/blog/html/writing-phpunit-tests-for-wordpress-plugins-wp-redirect-and-continuing-after-php-errors.htm
|
// more see in https://www.analysisandsolutions.com/blog/html/writing-phpunit-tests-for-wordpress-plugins-wp-redirect-and-continuing-after-php-errors.htm
|
||||||
|
|
||||||
// 2.
|
// 2.
|
||||||
// the Symfony used the HeaderMock.php
|
// the Symfony used the HeaderMock.php
|
||||||
|
|
||||||
// 3.
|
// 3.
|
||||||
// not run the eclipse will held, and travis-ci.org Searching for coverage reports
|
// not run the eclipse will held, and travis-ci.org Searching for coverage reports
|
||||||
// **> Python coverage not found
|
// **> Python coverage not found
|
||||||
// **> No coverage report found.
|
// **> No coverage report found.
|
||||||
// add the
|
// add the
|
||||||
// /**
|
// /**
|
||||||
// * @runInSeparateProcess
|
// * @runInSeparateProcess
|
||||||
// */
|
// */
|
||||||
if (!$this->default_return_type) {
|
if (!$this->default_return_type) {
|
||||||
$this->default_return_type = Config::get('default_return_type');
|
$this->default_return_type = Config::get('default_return_type');
|
||||||
}
|
}
|
||||||
if (!$this->default_ajax_return) {
|
if (!$this->default_ajax_return) {
|
||||||
$this->default_ajax_return = Config::get('default_ajax_return');
|
$this->default_ajax_return = Config::get('default_ajax_return');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the fixture, for example, closes a network connection.
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
* This method is called after a test is executed.
|
* This method is called after a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
Config::set('default_ajax_return', $this->default_ajax_return);
|
Config::set('default_ajax_return', $this->default_ajax_return);
|
||||||
Config::set('default_return_type', $this->default_return_type);
|
Config::set('default_return_type', $this->default_return_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Response::send
|
* @covers think\Response::send
|
||||||
* @todo Implement testSend().
|
* @todo Implement testSend().
|
||||||
*/
|
*/
|
||||||
public function testSend()
|
public function testSend()
|
||||||
{
|
{
|
||||||
$dataArr = [];
|
$dataArr = [];
|
||||||
$dataArr["key"] = "value";
|
$dataArr["key"] = "value";
|
||||||
|
|
||||||
$response = Response::create($dataArr, 'json');
|
$response = Response::create($dataArr, 'json');
|
||||||
$result = $response->getContent();
|
$result = $response->getContent();
|
||||||
$this->assertEquals('{"key":"value"}', $result);
|
$this->assertEquals('{"key":"value"}', $result);
|
||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
$request->get(['callback' => 'callback']);
|
$request->get(['callback' => 'callback']);
|
||||||
$response = Response::create($dataArr, 'jsonp');
|
$response = Response::create($dataArr, 'jsonp');
|
||||||
$result = $response->getContent();
|
$result = $response->getContent();
|
||||||
$this->assertEquals('callback({"key":"value"});', $result);
|
$this->assertEquals('callback({"key":"value"});', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,319 +1,319 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session测试
|
* Session测试
|
||||||
* @author 大漠 <zhylninc@gmail.com>
|
* @author 大漠 <zhylninc@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
use think\Session;
|
use think\Session;
|
||||||
|
|
||||||
class sessionTest extends \PHPUnit_Framework_TestCase
|
class sessionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \think\Session
|
* @var \think\Session
|
||||||
*/
|
*/
|
||||||
protected $object;
|
protected $object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
* This method is called before a test is executed.
|
* This method is called before a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// $this->object = new Session ();
|
// $this->object = new Session ();
|
||||||
// register_shutdown_function ( function () {
|
// register_shutdown_function ( function () {
|
||||||
// } ); // 此功能无法取消,需要回调函数配合。
|
// } ); // 此功能无法取消,需要回调函数配合。
|
||||||
set_exception_handler(function () {});
|
set_exception_handler(function () {});
|
||||||
set_error_handler(function () {});
|
set_error_handler(function () {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the fixture, for example, closes a network connection.
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
* This method is called after a test is executed.
|
* This method is called after a test is executed.
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
register_shutdown_function('think\Error::appShutdown');
|
register_shutdown_function('think\Error::appShutdown');
|
||||||
set_error_handler('think\Error::appError');
|
set_error_handler('think\Error::appError');
|
||||||
set_exception_handler('think\Error::appException');
|
set_exception_handler('think\Error::appException');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::prefix
|
* @covers think\Session::prefix
|
||||||
*
|
*
|
||||||
* @todo Implement testPrefix().
|
* @todo Implement testPrefix().
|
||||||
*/
|
*/
|
||||||
public function testPrefix()
|
public function testPrefix()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
Session::prefix('think_');
|
Session::prefix('think_');
|
||||||
|
|
||||||
$this->assertEquals('think_', Session::prefix());
|
$this->assertEquals('think_', Session::prefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::init
|
* @covers think\Session::init
|
||||||
*
|
*
|
||||||
* @todo Implement testInit().
|
* @todo Implement testInit().
|
||||||
*/
|
*/
|
||||||
public function testInit()
|
public function testInit()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
$config = [
|
$config = [
|
||||||
// cookie 名称前缀
|
// cookie 名称前缀
|
||||||
'prefix' => 'think_',
|
'prefix' => 'think_',
|
||||||
// cookie 保存时间
|
// cookie 保存时间
|
||||||
'expire' => 60,
|
'expire' => 60,
|
||||||
// cookie 保存路径
|
// cookie 保存路径
|
||||||
'path' => '/path/to/test/session/',
|
'path' => '/path/to/test/session/',
|
||||||
// cookie 有效域名
|
// cookie 有效域名
|
||||||
'domain' => '.thinkphp.cn',
|
'domain' => '.thinkphp.cn',
|
||||||
'var_session_id' => 'sessionidtest',
|
'var_session_id' => 'sessionidtest',
|
||||||
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
|
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
|
||||||
'name' => 'session_name',
|
'name' => 'session_name',
|
||||||
'use_trans_sid' => '1',
|
'use_trans_sid' => '1',
|
||||||
'use_cookies' => '1',
|
'use_cookies' => '1',
|
||||||
'cache_limiter' => '60',
|
'cache_limiter' => '60',
|
||||||
'cache_expire' => '60',
|
'cache_expire' => '60',
|
||||||
'type' => '', // memcache
|
'type' => '', // memcache
|
||||||
'namespace' => '\\think\\session\\driver\\', // ?
|
'namespace' => '\\think\\session\\driver\\', // ?
|
||||||
'auto_start' => '1',
|
'auto_start' => '1',
|
||||||
];
|
];
|
||||||
|
|
||||||
$_REQUEST[$config['var_session_id']] = $config['id'];
|
$_REQUEST[$config['var_session_id']] = $config['id'];
|
||||||
Session::init($config);
|
Session::init($config);
|
||||||
|
|
||||||
// 开始断言
|
// 开始断言
|
||||||
$this->assertEquals($config['prefix'], Session::prefix());
|
$this->assertEquals($config['prefix'], Session::prefix());
|
||||||
$this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]);
|
$this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]);
|
||||||
$this->assertEquals($config['name'], session_name());
|
$this->assertEquals($config['name'], session_name());
|
||||||
|
|
||||||
$this->assertEquals($config['path'], session_save_path());
|
$this->assertEquals($config['path'], session_save_path());
|
||||||
$this->assertEquals($config['use_cookies'], ini_get('session.use_cookies'));
|
$this->assertEquals($config['use_cookies'], ini_get('session.use_cookies'));
|
||||||
$this->assertEquals($config['domain'], ini_get('session.cookie_domain'));
|
$this->assertEquals($config['domain'], ini_get('session.cookie_domain'));
|
||||||
$this->assertEquals($config['expire'], ini_get('session.gc_maxlifetime'));
|
$this->assertEquals($config['expire'], ini_get('session.gc_maxlifetime'));
|
||||||
$this->assertEquals($config['expire'], ini_get('session.cookie_lifetime'));
|
$this->assertEquals($config['expire'], ini_get('session.cookie_lifetime'));
|
||||||
|
|
||||||
$this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter']));
|
$this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter']));
|
||||||
$this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire']));
|
$this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire']));
|
||||||
|
|
||||||
// 检测分支
|
// 检测分支
|
||||||
$_REQUEST[$config['var_session_id']] = null;
|
$_REQUEST[$config['var_session_id']] = null;
|
||||||
session_write_close();
|
session_write_close();
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
Session::init($config);
|
Session::init($config);
|
||||||
|
|
||||||
// 测试auto_start
|
// 测试auto_start
|
||||||
// PHP_SESSION_DISABLED
|
// PHP_SESSION_DISABLED
|
||||||
// PHP_SESSION_NONE
|
// PHP_SESSION_NONE
|
||||||
// PHP_SESSION_ACTIVE
|
// PHP_SESSION_ACTIVE
|
||||||
// session_status()
|
// session_status()
|
||||||
if (strstr(PHP_VERSION, 'hhvm')) {
|
if (strstr(PHP_VERSION, 'hhvm')) {
|
||||||
$this->assertEquals('', ini_get('session.auto_start'));
|
$this->assertEquals('', ini_get('session.auto_start'));
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals(0, ini_get('session.auto_start'));
|
$this->assertEquals(0, ini_get('session.auto_start'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid'));
|
$this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid'));
|
||||||
|
|
||||||
Session::init($config);
|
Session::init($config);
|
||||||
$this->assertEquals($config['id'], session_id());
|
$this->assertEquals($config['id'], session_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单独重现异常
|
* 单独重现异常
|
||||||
* @expectedException \think\Exception
|
* @expectedException \think\Exception
|
||||||
*/
|
*/
|
||||||
public function testException()
|
public function testException()
|
||||||
{
|
{
|
||||||
$config = [
|
$config = [
|
||||||
// cookie 名称前缀
|
// cookie 名称前缀
|
||||||
'prefix' => 'think_',
|
'prefix' => 'think_',
|
||||||
// cookie 保存时间
|
// cookie 保存时间
|
||||||
'expire' => 0,
|
'expire' => 0,
|
||||||
// cookie 保存路径
|
// cookie 保存路径
|
||||||
'path' => '/path/to/test/session/',
|
'path' => '/path/to/test/session/',
|
||||||
// cookie 有效域名
|
// cookie 有效域名
|
||||||
'domain' => '.thinkphp.cn',
|
'domain' => '.thinkphp.cn',
|
||||||
'var_session_id' => 'sessionidtest',
|
'var_session_id' => 'sessionidtest',
|
||||||
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
|
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
|
||||||
'name' => 'session_name',
|
'name' => 'session_name',
|
||||||
'use_trans_sid' => '1',
|
'use_trans_sid' => '1',
|
||||||
'use_cookies' => '1',
|
'use_cookies' => '1',
|
||||||
'cache_limiter' => '60',
|
'cache_limiter' => '60',
|
||||||
'cache_expire' => '60',
|
'cache_expire' => '60',
|
||||||
'type' => '\\think\\session\\driver\\Memcache', //
|
'type' => '\\think\\session\\driver\\Memcache', //
|
||||||
'auto_start' => '1',
|
'auto_start' => '1',
|
||||||
];
|
];
|
||||||
|
|
||||||
// 测试session驱动是否存在
|
// 测试session驱动是否存在
|
||||||
// @expectedException 异常类名
|
// @expectedException 异常类名
|
||||||
$this->setExpectedException('\think\exception\ClassNotFoundException', 'error session handler');
|
$this->setExpectedException('\think\exception\ClassNotFoundException', 'error session handler');
|
||||||
|
|
||||||
Session::init($config);
|
Session::init($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::set
|
* @covers think\Session::set
|
||||||
*
|
*
|
||||||
* @todo Implement testSet().
|
* @todo Implement testSet().
|
||||||
*/
|
*/
|
||||||
public function testSet()
|
public function testSet()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
Session::set('sessionname', 'sessionvalue');
|
Session::set('sessionname', 'sessionvalue');
|
||||||
$this->assertEquals('sessionvalue', $_SESSION['sessionname']);
|
$this->assertEquals('sessionvalue', $_SESSION['sessionname']);
|
||||||
|
|
||||||
Session::set('sessionnamearr.subname', 'sessionvalue');
|
Session::set('sessionnamearr.subname', 'sessionvalue');
|
||||||
$this->assertEquals('sessionvalue', $_SESSION['sessionnamearr']['subname']);
|
$this->assertEquals('sessionvalue', $_SESSION['sessionnamearr']['subname']);
|
||||||
|
|
||||||
Session::set('sessionnameper', 'sessionvalue', 'think_');
|
Session::set('sessionnameper', 'sessionvalue', 'think_');
|
||||||
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnameper']);
|
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnameper']);
|
||||||
|
|
||||||
Session::set('sessionnamearrper.subname', 'sessionvalue', 'think_');
|
Session::set('sessionnamearrper.subname', 'sessionvalue', 'think_');
|
||||||
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnamearrper']['subname']);
|
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnamearrper']['subname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::get
|
* @covers think\Session::get
|
||||||
*
|
*
|
||||||
* @todo Implement testGet().
|
* @todo Implement testGet().
|
||||||
*/
|
*/
|
||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
|
|
||||||
Session::set('sessionnameget', 'sessionvalue');
|
Session::set('sessionnameget', 'sessionvalue');
|
||||||
$this->assertEquals(Session::get('sessionnameget'), $_SESSION['sessionnameget']);
|
$this->assertEquals(Session::get('sessionnameget'), $_SESSION['sessionnameget']);
|
||||||
|
|
||||||
Session::set('sessionnamegetarr.subname', 'sessionvalue');
|
Session::set('sessionnamegetarr.subname', 'sessionvalue');
|
||||||
$this->assertEquals(Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']);
|
$this->assertEquals(Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']);
|
||||||
|
|
||||||
Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_');
|
Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_');
|
||||||
$this->assertEquals(Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']);
|
$this->assertEquals(Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']);
|
||||||
|
|
||||||
Session::set('sessionnamegetper', 'sessionvalue', 'think_');
|
Session::set('sessionnamegetper', 'sessionvalue', 'think_');
|
||||||
$this->assertEquals(Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']);
|
$this->assertEquals(Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']);
|
||||||
|
|
||||||
Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_');
|
Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_');
|
||||||
$this->assertEquals(Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']);
|
$this->assertEquals(Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPull()
|
public function testPull()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
Session::set('sessionnamedel', 'sessionvalue');
|
Session::set('sessionnamedel', 'sessionvalue');
|
||||||
$this->assertEquals('sessionvalue', Session::pull('sessionnameget'));
|
$this->assertEquals('sessionvalue', Session::pull('sessionnameget'));
|
||||||
$this->assertNull(Session::get('sessionnameget'));
|
$this->assertNull(Session::get('sessionnameget'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::delete
|
* @covers think\Session::delete
|
||||||
*
|
*
|
||||||
* @todo Implement testDelete().
|
* @todo Implement testDelete().
|
||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
Session::set('sessionnamedel', 'sessionvalue');
|
Session::set('sessionnamedel', 'sessionvalue');
|
||||||
Session::delete('sessionnamedel');
|
Session::delete('sessionnamedel');
|
||||||
$this->assertEmpty($_SESSION['sessionnamedel']);
|
$this->assertEmpty($_SESSION['sessionnamedel']);
|
||||||
|
|
||||||
Session::set('sessionnamedelarr.subname', 'sessionvalue');
|
Session::set('sessionnamedelarr.subname', 'sessionvalue');
|
||||||
Session::delete('sessionnamedelarr.subname');
|
Session::delete('sessionnamedelarr.subname');
|
||||||
$this->assertEmpty($_SESSION['sessionnamedelarr']['subname']);
|
$this->assertEmpty($_SESSION['sessionnamedelarr']['subname']);
|
||||||
|
|
||||||
Session::set('sessionnamedelper', 'sessionvalue', 'think_');
|
Session::set('sessionnamedelper', 'sessionvalue', 'think_');
|
||||||
Session::delete('sessionnamedelper', 'think_');
|
Session::delete('sessionnamedelper', 'think_');
|
||||||
$this->assertEmpty($_SESSION['think_']['sessionnamedelper']);
|
$this->assertEmpty($_SESSION['think_']['sessionnamedelper']);
|
||||||
|
|
||||||
Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_');
|
Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_');
|
||||||
Session::delete('sessionnamedelperarr.subname', 'think_');
|
Session::delete('sessionnamedelperarr.subname', 'think_');
|
||||||
$this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']);
|
$this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::clear
|
* @covers think\Session::clear
|
||||||
*
|
*
|
||||||
* @todo Implement testClear().
|
* @todo Implement testClear().
|
||||||
*/
|
*/
|
||||||
public function testClear()
|
public function testClear()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
|
|
||||||
Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
|
Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
|
||||||
Session::clear('think_');
|
Session::clear('think_');
|
||||||
$this->assertNull($_SESSION['think_']);
|
$this->assertNull($_SESSION['think_']);
|
||||||
|
|
||||||
Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
|
Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
|
||||||
Session::clear();
|
Session::clear();
|
||||||
$this->assertEmpty($_SESSION);
|
$this->assertEmpty($_SESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::has
|
* @covers think\Session::has
|
||||||
*
|
*
|
||||||
* @todo Implement testHas().
|
* @todo Implement testHas().
|
||||||
*/
|
*/
|
||||||
public function testHas()
|
public function testHas()
|
||||||
{
|
{
|
||||||
Session::prefix(null);
|
Session::prefix(null);
|
||||||
Session::set('sessionnamehas', 'sessionvalue');
|
Session::set('sessionnamehas', 'sessionvalue');
|
||||||
$this->assertTrue(Session::has('sessionnamehas'));
|
$this->assertTrue(Session::has('sessionnamehas'));
|
||||||
|
|
||||||
Session::set('sessionnamehasarr.subname', 'sessionvalue');
|
Session::set('sessionnamehasarr.subname', 'sessionvalue');
|
||||||
$this->assertTrue(Session::has('sessionnamehasarr.subname'));
|
$this->assertTrue(Session::has('sessionnamehasarr.subname'));
|
||||||
|
|
||||||
Session::set('sessionnamehasper', 'sessionvalue', 'think_');
|
Session::set('sessionnamehasper', 'sessionvalue', 'think_');
|
||||||
$this->assertTrue(Session::has('sessionnamehasper', 'think_'));
|
$this->assertTrue(Session::has('sessionnamehasper', 'think_'));
|
||||||
|
|
||||||
Session::set('sessionnamehasarrper.subname', 'sessionvalue', 'think_');
|
Session::set('sessionnamehasarrper.subname', 'sessionvalue', 'think_');
|
||||||
$this->assertTrue(Session::has('sessionnamehasarrper.subname', 'think_'));
|
$this->assertTrue(Session::has('sessionnamehasarrper.subname', 'think_'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::pause
|
* @covers think\Session::pause
|
||||||
*
|
*
|
||||||
* @todo Implement testPause().
|
* @todo Implement testPause().
|
||||||
*/
|
*/
|
||||||
public function testPause()
|
public function testPause()
|
||||||
{
|
{
|
||||||
Session::pause();
|
Session::pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::start
|
* @covers think\Session::start
|
||||||
*
|
*
|
||||||
* @todo Implement testStart().
|
* @todo Implement testStart().
|
||||||
*/
|
*/
|
||||||
public function testStart()
|
public function testStart()
|
||||||
{
|
{
|
||||||
Session::start();
|
Session::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers think\Session::destroy
|
* @covers think\Session::destroy
|
||||||
*
|
*
|
||||||
* @todo Implement testDestroy().
|
* @todo Implement testDestroy().
|
||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
Session::set('sessionnamedestroy', 'sessionvalue');
|
Session::set('sessionnamedestroy', 'sessionvalue');
|
||||||
Session::destroy();
|
Session::destroy();
|
||||||
$this->assertEmpty($_SESSION['sessionnamedestroy']);
|
$this->assertEmpty($_SESSION['sessionnamedestroy']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace tests\thinkphp\library\think\tempplate\taglib;
|
|||||||
use think\Template;
|
use think\Template;
|
||||||
use think\template\taglib\Cx;
|
use think\template\taglib\Cx;
|
||||||
|
|
||||||
class templateTest extends \PHPUnit_Framework_TestCase
|
class cxTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testPhp()
|
public function testPhp()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,76 +1,76 @@
|
|||||||
<?php
|
<?php
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* view测试
|
* view测试
|
||||||
* @author mahuan <mahuan@d1web.top>
|
* @author mahuan <mahuan@d1web.top>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace tests\thinkphp\library\think;
|
namespace tests\thinkphp\library\think;
|
||||||
|
|
||||||
class viewTest extends \PHPUnit_Framework_TestCase
|
class viewTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 句柄测试
|
* 句柄测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testGetInstance()
|
public function testGetInstance()
|
||||||
{
|
{
|
||||||
\think\Cookie::get('a');
|
\think\Cookie::get('a');
|
||||||
$view_instance = \think\View::instance();
|
$view_instance = \think\View::instance();
|
||||||
$this->assertInstanceOf('\think\view', $view_instance, 'instance方法返回错误');
|
$this->assertInstanceOf('\think\view', $view_instance, 'instance方法返回错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试变量赋值
|
* 测试变量赋值
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testAssign()
|
public function testAssign()
|
||||||
{
|
{
|
||||||
$view_instance = \think\View::instance();
|
$view_instance = \think\View::instance();
|
||||||
$view_instance->key = 'value';
|
$view_instance->key = 'value';
|
||||||
$this->assertTrue(isset($view_instance->key));
|
$this->assertTrue(isset($view_instance->key));
|
||||||
$this->assertEquals('value', $view_instance->key);
|
$this->assertEquals('value', $view_instance->key);
|
||||||
$data = $view_instance->assign(array('key' => 'value'));
|
$data = $view_instance->assign(array('key' => 'value'));
|
||||||
$data = $view_instance->assign('key2', 'value2');
|
$data = $view_instance->assign('key2', 'value2');
|
||||||
//测试私有属性
|
//测试私有属性
|
||||||
$expect_data = array('key' => 'value', 'key2' => 'value2');
|
$expect_data = array('key' => 'value', 'key2' => 'value2');
|
||||||
$this->assertAttributeEquals($expect_data, 'data', $view_instance);
|
$this->assertAttributeEquals($expect_data, 'data', $view_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试引擎设置
|
* 测试引擎设置
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function testEngine()
|
public function testEngine()
|
||||||
{
|
{
|
||||||
$view_instance = \think\View::instance();
|
$view_instance = \think\View::instance();
|
||||||
$data = $view_instance->engine('php');
|
$data = $view_instance->engine('php');
|
||||||
$data = $view_instance->engine(['type' => 'php', 'view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
|
$data = $view_instance->engine(['type' => 'php', 'view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
|
||||||
$php_engine = new \think\view\driver\Php(['view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
|
$php_engine = new \think\view\driver\Php(['view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]);
|
||||||
$this->assertAttributeEquals($php_engine, 'engine', $view_instance);
|
$this->assertAttributeEquals($php_engine, 'engine', $view_instance);
|
||||||
//测试模板引擎驱动
|
//测试模板引擎驱动
|
||||||
$data = $view_instance->engine(['type' => 'think', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
|
$data = $view_instance->engine(['type' => 'think', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
|
||||||
$think_engine = new \think\view\driver\Think(['view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
|
$think_engine = new \think\view\driver\Think(['view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]);
|
||||||
$this->assertAttributeEquals($think_engine, 'engine', $view_instance);
|
$this->assertAttributeEquals($think_engine, 'engine', $view_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReplace()
|
public function testReplace()
|
||||||
{
|
{
|
||||||
$view_instance = \think\View::instance();
|
$view_instance = \think\View::instance();
|
||||||
$view_instance->replace('string', 'replace')->display('string');
|
$view_instance->replace('string', 'replace')->display('string');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user