mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-01 11:17:54 +08:00
Fixed test cases for session.
This commit is contained in:
parent
9cfd30f9bc
commit
2d6704d6e1
@ -17,6 +17,7 @@ use Hyperf\HttpMessage\Server\Request;
|
||||
use Hyperf\Session\Session;
|
||||
use Hyperf\Session\SessionManager;
|
||||
use Hyperf\Utils\Str;
|
||||
use HyperfTest\Session\Stub\MockStub;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
@ -42,7 +43,7 @@ class SessionManagerTest extends TestCase
|
||||
public function testParseSessionId()
|
||||
{
|
||||
$request = new Request('get', '/');
|
||||
$sessionManager = new SessionManager(Mockery::mock(ContainerInterface::class), Mockery::mock(ConfigInterface::class));
|
||||
$sessionManager = new SessionManager(Mockery::mock(ContainerInterface::class), MockStub::makeConfig());
|
||||
$reflectionClass = new ReflectionClass(SessionManager::class);
|
||||
$parseSessionIdMethod = $reflectionClass->getMethod('parseSessionId');
|
||||
$parseSessionIdMethod->setAccessible(true);
|
||||
|
@ -13,19 +13,19 @@ declare(strict_types=1);
|
||||
namespace HyperfTest\Session;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\HttpMessage\Uri\Uri;
|
||||
use HyperfTest\Session\Stub\FooHandler;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Contract\SessionInterface;
|
||||
use Hyperf\HttpMessage\Cookie\Cookie;
|
||||
use Hyperf\HttpMessage\Server\Request;
|
||||
use Hyperf\HttpMessage\Server\Response;
|
||||
use Hyperf\HttpMessage\Uri\Uri;
|
||||
use Hyperf\Session\Handler\FileHandler;
|
||||
use Hyperf\Session\Middleware\SessionMiddleware;
|
||||
use Hyperf\Session\Session;
|
||||
use Hyperf\Session\SessionManager;
|
||||
use Hyperf\Utils\Context;
|
||||
use Hyperf\Utils\Filesystem\Filesystem;
|
||||
use HyperfTest\Session\Stub\FooHandler;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
@ -61,6 +61,7 @@ class SessionMiddlewareTest extends TestCase
|
||||
$config->shouldReceive('get')->with('session.handler')->andReturn(FooHandler::class);
|
||||
$config->shouldReceive('has')->with('session.handler')->andReturn(true);
|
||||
$config->shouldReceive('get')->with('session.options.expire_on_close')->andReturn(1);
|
||||
$config->shouldReceive('get')->with('session.options.session_name', 'HYPERF_SESSION_ID')->andReturn('HYPERF_SESSION_ID');
|
||||
$sessionManager = new SessionManager($container, $config);
|
||||
$middleware = new SessionMiddleware($sessionManager, $config);
|
||||
$response = $middleware->process($request, $requestHandler);
|
||||
@ -103,6 +104,7 @@ class SessionMiddlewareTest extends TestCase
|
||||
$config->shouldReceive('get')->with('session.handler')->andReturn(FooHandler::class);
|
||||
$config->shouldReceive('has')->with('session.handler')->andReturn(true);
|
||||
$config->shouldReceive('get')->with('session.options.expire_on_close')->andReturn(0);
|
||||
$config->shouldReceive('get')->with('session.options.session_name', 'HYPERF_SESSION_ID')->andReturn('HYPERF_SESSION_ID');
|
||||
$sessionManager = new SessionManager($container, $config);
|
||||
$middleware = new SessionMiddleware($sessionManager, $config);
|
||||
$time = time();
|
||||
|
34
src/session/tests/Stub/MockStub.php
Normal file
34
src/session/tests/Stub/MockStub.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace HyperfTest\Session\Stub;
|
||||
|
||||
use Hyperf\Config\Config;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
|
||||
class MockStub
|
||||
{
|
||||
public static function makeConfig(): ConfigInterface
|
||||
{
|
||||
return new Config([
|
||||
'session' => [
|
||||
'handler' => Handler\FileHandler::class,
|
||||
'options' => [
|
||||
'connection' => 'default',
|
||||
'path' => BASE_PATH . '/runtime/session',
|
||||
'gc_maxlifetime' => 1200,
|
||||
'session_name' => 'HYPERF_SESSION_ID',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user