From 2d6704d6e1e0a937c1103485059f0dd9b4b97584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Mon, 16 Mar 2020 14:59:59 +0800 Subject: [PATCH] Fixed test cases for session. --- src/session/tests/SessionManagerTest.php | 3 +- src/session/tests/SessionMiddlewareTest.php | 6 ++-- src/session/tests/Stub/MockStub.php | 34 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/session/tests/Stub/MockStub.php diff --git a/src/session/tests/SessionManagerTest.php b/src/session/tests/SessionManagerTest.php index 203176a9d..e532dcbff 100644 --- a/src/session/tests/SessionManagerTest.php +++ b/src/session/tests/SessionManagerTest.php @@ -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); diff --git a/src/session/tests/SessionMiddlewareTest.php b/src/session/tests/SessionMiddlewareTest.php index e0facce48..23c870f95 100644 --- a/src/session/tests/SessionMiddlewareTest.php +++ b/src/session/tests/SessionMiddlewareTest.php @@ -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(); diff --git a/src/session/tests/Stub/MockStub.php b/src/session/tests/Stub/MockStub.php new file mode 100644 index 000000000..1dfecd972 --- /dev/null +++ b/src/session/tests/Stub/MockStub.php @@ -0,0 +1,34 @@ + [ + 'handler' => Handler\FileHandler::class, + 'options' => [ + 'connection' => 'default', + 'path' => BASE_PATH . '/runtime/session', + 'gc_maxlifetime' => 1200, + 'session_name' => 'HYPERF_SESSION_ID', + ], + ], + ]); + } +}