forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySessionHandlerTest.php
More file actions
114 lines (81 loc) · 3.03 KB
/
ArraySessionHandlerTest.php
File metadata and controls
114 lines (81 loc) · 3.03 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Illuminate\Tests\Session;
use Illuminate\Session\ArraySessionHandler;
use Illuminate\Support\Carbon;
use PHPUnit\Framework\TestCase;
use SessionHandlerInterface;
class ArraySessionHandlerTest extends TestCase
{
public function test_it_implements_the_session_handler_interface()
{
$this->assertInstanceOf(SessionHandlerInterface::class, new ArraySessionHandler(10));
}
public function test_it_initializes_the_session()
{
$handler = new ArraySessionHandler(10);
$this->assertTrue($handler->open('', ''));
}
public function test_it_closes_the_session()
{
$handler = new ArraySessionHandler(10);
$this->assertTrue($handler->close());
}
public function test_it_reads_data_from_the_session()
{
$handler = new ArraySessionHandler(10);
$handler->write('foo', 'bar');
$this->assertEquals('bar', $handler->read('foo'));
}
public function test_it_reads_data_from_an_almost_expired_session()
{
$handler = new ArraySessionHandler(10);
$handler->write('foo', 'bar');
Carbon::setTestNow(Carbon::now()->addMinutes(10));
$this->assertEquals('bar', $handler->read('foo'));
Carbon::setTestNow();
}
public function test_it_reads_data_from_an_expired_session()
{
$handler = new ArraySessionHandler(10);
$handler->write('foo', 'bar');
Carbon::setTestNow(Carbon::now()->addMinutes(10)->addSecond());
$this->assertEquals('', $handler->read('foo'));
Carbon::setTestNow();
}
public function test_it_reads_data_from_a_non_existing_session()
{
$handler = new ArraySessionHandler(10);
$this->assertEquals('', $handler->read('foo'));
}
public function test_it_writes_session_data()
{
$handler = new ArraySessionHandler(10);
$this->assertTrue($handler->write('foo', 'bar'));
$this->assertEquals('bar', $handler->read('foo'));
$this->assertTrue($handler->write('foo', 'baz'));
$this->assertEquals('baz', $handler->read('foo'));
}
public function test_it_destroys_a_session()
{
$handler = new ArraySessionHandler(10);
$this->assertTrue($handler->destroy('foo'));
$handler->write('foo', 'bar');
$this->assertTrue($handler->destroy('foo'));
$this->assertEquals('', $handler->read('foo'));
}
public function test_it_cleans_up_old_sessions()
{
$handler = new ArraySessionHandler(10);
$this->assertTrue($handler->gc(300));
$handler->write('foo', 'bar');
$this->assertTrue($handler->gc(300));
$this->assertEquals('bar', $handler->read('foo'));
Carbon::setTestNow(Carbon::now()->addSecond());
$handler->write('baz', 'qux');
Carbon::setTestNow(Carbon::now()->addMinutes(5));
$this->assertTrue($handler->gc(300));
$this->assertEquals('', $handler->read('foo'));
$this->assertEquals('qux', $handler->read('baz'));
Carbon::setTestNow();
}
}