修正命名空间、版权注释

This commit is contained in:
7IN0SAN9
2016-01-20 11:14:19 +08:00
parent 6120be3671
commit cc530a98a3
15 changed files with 215 additions and 156 deletions

View File

@@ -6,14 +6,17 @@
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 大漠 <zhylninc@gmail.com>
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-14 at 02:40:08.
* Session测试
* @author 大漠 <zhylninc@gmail.com>
*/
class SessionTest extends \PHPUnit_Framework_TestCase
namespace tests\thinkphp\library\think;
class sessionTest extends \PHPUnit_Framework_TestCase
{
/**
@@ -55,7 +58,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
{
\think\Session::prefix(null);
\think\Session::prefix('think_');
$this->assertEquals('think_', \think\Session::prefix());
}
@@ -69,58 +72,58 @@ class SessionTest extends \PHPUnit_Framework_TestCase
\think\Session::prefix(null);
$config = [
// cookie 名称前缀
'prefix' => 'think_',
'prefix' => 'think_',
// cookie 保存时间
'expire' => 60,
'expire' => 60,
// cookie 保存路径
'path' => '/path/to/test/session/',
'path' => '/path/to/test/session/',
// cookie 有效域名
'domain' => '.thinkphp.cn',
'domain' => '.thinkphp.cn',
'var_session_id' => 'sessionidtest',
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
'name' => 'session_name',
'use_trans_sid' => '1',
'use_cookies' => '1',
'cache_limiter' => '60',
'cache_expire' => '60',
'type' => '', // memcache
'namespace' => '\\think\\session\\driver\\', // ?
'auto_start' => '1'
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
'name' => 'session_name',
'use_trans_sid' => '1',
'use_cookies' => '1',
'cache_limiter' => '60',
'cache_expire' => '60',
'type' => '', // memcache
'namespace' => '\\think\\session\\driver\\', // ?
'auto_start' => '1',
];
$_REQUEST[$config['var_session_id']] = $config['id'];
\think\Session::init($config);
// 开始断言
$this->assertEquals($config['prefix'], \think\Session::prefix());
$this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]);
$this->assertEquals($config['name'], session_name());
$this->assertEquals($config['path'], session_save_path());
$this->assertEquals($config['use_cookies'], ini_get('session.use_cookies'));
$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.cookie_lifetime'));
$this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter']));
$this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire']));
// 检测分支
$_REQUEST[$config['var_session_id']] = null;
session_write_close();
session_destroy();
\think\Session::init($config);
// 测试auto_start
// PHP_SESSION_DISABLED
// PHP_SESSION_NONE
// PHP_SESSION_ACTIVE
// session_status()
$this->assertEquals(0, ini_get('session.auto_start'));
$this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid'));
\think\Session::init($config);
$this->assertEquals($config['id'], session_id());
}
@@ -133,29 +136,29 @@ class SessionTest extends \PHPUnit_Framework_TestCase
{
$config = [
// cookie 名称前缀
'prefix' => 'think_',
'prefix' => 'think_',
// cookie 保存时间
'expire' => 0,
'expire' => 0,
// cookie 保存路径
'path' => '/path/to/test/session/',
'path' => '/path/to/test/session/',
// cookie 有效域名
'domain' => '.thinkphp.cn',
'domain' => '.thinkphp.cn',
'var_session_id' => 'sessionidtest',
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
'name' => 'session_name',
'use_trans_sid' => '1',
'use_cookies' => '1',
'cache_limiter' => '60',
'cache_expire' => '60',
'type' => 'memcache', //
'namespace' => '\\think\\session\\driver\\', // ?
'auto_start' => '1'
'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1',
'name' => 'session_name',
'use_trans_sid' => '1',
'use_cookies' => '1',
'cache_limiter' => '60',
'cache_expire' => '60',
'type' => 'memcache', //
'namespace' => '\\think\\session\\driver\\', // ?
'auto_start' => '1',
];
// 测试session驱动是否存在
// @expectedException 异常类名
$this->setExpectedException('\think\Exception', 'error session handler', 11700);
\think\Session::init($config);
}
@@ -169,13 +172,13 @@ class SessionTest extends \PHPUnit_Framework_TestCase
\think\Session::prefix(null);
\think\Session::set('sessionname', 'sessionvalue');
$this->assertEquals('sessionvalue', $_SESSION['sessionname']);
\think\Session::set('sessionnamearr.subname', 'sessionvalue');
$this->assertEquals('sessionvalue', $_SESSION['sessionnamearr']['subname']);
\think\Session::set('sessionnameper', 'sessionvalue', 'think_');
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnameper']);
\think\Session::set('sessionnamearrper.subname', 'sessionvalue', 'think_');
$this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnamearrper']['subname']);
}
@@ -188,19 +191,19 @@ class SessionTest extends \PHPUnit_Framework_TestCase
public function testGet()
{
\think\Session::prefix(null);
\think\Session::set('sessionnameget', 'sessionvalue');
$this->assertEquals(\think\Session::get('sessionnameget'), $_SESSION['sessionnameget']);
\think\Session::set('sessionnamegetarr.subname', 'sessionvalue');
$this->assertEquals(\think\Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']);
\think\Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_');
$this->assertEquals(\think\Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']);
\think\Session::set('sessionnamegetper', 'sessionvalue', 'think_');
$this->assertEquals(\think\Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']);
\think\Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_');
$this->assertEquals(\think\Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']);
}
@@ -216,15 +219,15 @@ class SessionTest extends \PHPUnit_Framework_TestCase
\think\Session::set('sessionnamedel', 'sessionvalue');
\think\Session::delete('sessionnamedel');
$this->assertEmpty($_SESSION['sessionnamedel']);
\think\Session::set('sessionnamedelarr.subname', 'sessionvalue');
\think\Session::delete('sessionnamedelarr.subname');
$this->assertEmpty($_SESSION['sessionnamedelarr']['subname']);
\think\Session::set('sessionnamedelper', 'sessionvalue', 'think_');
\think\Session::delete('sessionnamedelper', 'think_');
$this->assertEmpty($_SESSION['think_']['sessionnamedelper']);
\think\Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_');
\think\Session::delete('sessionnamedelperarr.subname', 'think_');
$this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']);
@@ -238,11 +241,11 @@ class SessionTest extends \PHPUnit_Framework_TestCase
public function testClear()
{
\think\Session::prefix(null);
\think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
\think\Session::clear('think_');
$this->assertNull($_SESSION['think_']);
\think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_');
\think\Session::clear();
$this->assertEmpty($_SESSION);
@@ -258,13 +261,13 @@ class SessionTest extends \PHPUnit_Framework_TestCase
\think\Session::prefix(null);
\think\Session::set('sessionnamehas', 'sessionvalue');
$this->assertTrue(\think\Session::has('sessionnamehas'));
\think\Session::set('sessionnamehasarr.subname', 'sessionvalue');
$this->assertTrue(\think\Session::has('sessionnamehasarr.subname'));
\think\Session::set('sessionnamehasper', 'sessionvalue', 'think_');
$this->assertTrue(\think\Session::has('sessionnamehasper', 'think_'));
\think\Session::set('sessionnamehasarrper.subname', 'sessionvalue', 'think_');
$this->assertTrue(\think\Session::has('sessionnamehasarrper.subname', 'think_'));
}
@@ -300,4 +303,4 @@ class SessionTest extends \PHPUnit_Framework_TestCase
\think\Session::destroy();
$this->assertEmpty($_SESSION['sessionnamedestroy']);
}
}
}