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', + ], + ], + ]); + } +}