Repository navigation
Expand file tree
/
Copy pathSessionManagerTest.php
More file actions
66 lines (60 loc) · 2.11 KB
/
Copy pathSessionManagerTest.php
File metadata and controls
66 lines (60 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Session;
use Hyperf\Contract\ConfigInterface;
use Hyperf\HttpMessage\Server\Request;
use Hyperf\Session\Session;
use Hyperf\Session\SessionManager;
use Hyperf\Stringable\Str;
use HyperfTest\Session\Stub\MockStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use ReflectionClass;
/**
* @internal
* @coversNothing
*/
#[CoversClass(SessionManager::class)]
/**
* @internal
* @coversNothing
*/
class SessionManagerTest extends TestCase
{
public function testSetterAndGetter()
{
$sessionManager = new SessionManager(Mockery::mock(ContainerInterface::class), Mockery::mock(ConfigInterface::class));
$sessionManager = $sessionManager->setSession($mockSession = Mockery::mock(Session::class));
$this->assertInstanceOf(SessionManager::class, $sessionManager);
$session = $sessionManager->getSession();
$this->assertInstanceOf(Session::class, $session);
$this->assertSame($mockSession, $session);
}
public function testParseSessionId()
{
$request = new Request('get', '/');
$sessionManager = new SessionManager(Mockery::mock(ContainerInterface::class), MockStub::makeConfig());
$reflectionClass = new ReflectionClass(SessionManager::class);
$parseSessionIdMethod = $reflectionClass->getMethod('parseSessionId');
$id = Str::random(40);
$this->assertSame($id, $parseSessionIdMethod->invoke($sessionManager, $request->withCookieParams([
'HYPERF_SESSION_ID' => $id,
])));
$this->assertSame('123', $parseSessionIdMethod->invoke($sessionManager, $request->withCookieParams([
'HYPERF_SESSION_ID' => 123,
])));
$this->assertNull($parseSessionIdMethod->invoke($sessionManager, $request->withCookieParams([
'foo' => 'bar',
])));
}
}