forked from jasny/session-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalSessionTest.php
More file actions
70 lines (52 loc) · 1.55 KB
/
Copy pathGlobalSessionTest.php
File metadata and controls
70 lines (52 loc) · 1.55 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
67
68
69
70
<?php
declare(strict_types=1);
namespace Jasny\Session\Tests;
use Jasny\Session\GlobalSession;
/**
* @covers \Jasny\Session\GlobalSession
*/
class GlobalSessionTest extends AbstractSessionTest
{
public function setUp(): void
{
$this->createTestSession();
$this->session = new GlobalSession();
session_start();
}
protected function createTestSession()
{
session_id('test');
session_start();
$_SESSION = ['foo' => 'bar'];
session_write_close();
}
public function tearDown(): void
{
if (session_status() === \PHP_SESSION_ACTIVE) {
session_destroy();
}
}
protected function assertSessionData(array $expected)
{
$this->assertEquals($expected, $_SESSION);
}
public function testArrayAccess()
{
$this->session['one'] = 1;
$this->session['two'] = 2;
$this->assertEquals(['foo' => 'bar', 'one' => 1, 'two' => 2], $_SESSION);
$this->assertEquals(1, $this->session['one']);
$this->assertTrue(isset($this->session['one']));
$this->assertFalse(isset($this->session['zero']));
unset($this->session['two']);
$this->assertEquals(['foo' => 'bar', 'one' => 1], $_SESSION);
unset($this->session['zero']); // No notice
}
public function testAssertStarted()
{
$this->session->stop();
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage("Session not started");
$this->session['one'] = 1;
}
}