-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFlashTest.php
More file actions
75 lines (61 loc) · 2.06 KB
/
Copy pathFlashTest.php
File metadata and controls
75 lines (61 loc) · 2.06 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
<?php
namespace Odan\Session\Test;
use Odan\Session\Flash;
use PHPUnit\Framework\TestCase;
class FlashTest extends TestCase
{
public function testAddAndGet(): void
{
$session = [];
$flash = new Flash($session);
$flash->add('key1', 'value1');
$flash->add('key2', 'value2');
$flash->add('key2', 'value3');
$this->assertSame([0 => 'value1'], $flash->get('key1'));
$this->assertSame([], $flash->get('key1'));
$this->assertSame([0 => 'value2', 1 => 'value3'], $flash->get('key2'));
$this->assertSame([], $flash->get('key1'));
$this->assertSame([], $flash->get('nada'));
}
public function testHas(): void
{
$session = [];
$flash = new Flash($session);
$flash->add('key1', 'value1');
$this->assertTrue($flash->has('key1'));
$this->assertTrue($flash->has('key1'));
$this->assertFalse($flash->has('key2'));
}
public function testAll(): void
{
$session = [];
$flash = new Flash($session);
$flash->add('key1', 'value1');
$flash->add('key1', 'value2');
$this->assertTrue($flash->has('key1'));
$this->assertSame(['key1' => [0 => 'value1', 1 => 'value2']], $flash->all());
$this->assertFalse($flash->has('key1'));
$this->assertSame([], $flash->all());
}
public function testSet(): void
{
$session = [];
$flash = new Flash($session);
$flash->set('key1', ['value1']);
$this->assertSame([0 => 'value1'], $flash->get('key1'));
$session = [];
$flash = new Flash($session);
$flash->set('key2', ['value1', 'value2']);
$this->assertSame([0 => 'value1', 1 => 'value2'], $flash->get('key2'));
}
public function testClear(): void
{
$session = [];
$flash = new Flash($session);
$flash->add('key1', 'value1');
$this->assertTrue($flash->has('key1'));
$flash->clear();
$this->assertFalse($flash->has('key1'));
$this->assertSame([], $flash->all());
}
}