1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Enjoys\Cookie; |
4
|
|
|
|
5
|
|
|
use Enjoys\Cookie\Exception; |
6
|
|
|
use Enjoys\Cookie\Expires; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class ExpiresTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
private $currentTimestamp = 1; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @dataProvider expiresData |
16
|
|
|
*/ |
17
|
|
|
public function testGetExpires($ttl, $expect) |
18
|
|
|
{ |
19
|
|
|
$expires = new Expires($ttl, $this->currentTimestamp); |
20
|
|
|
$this->assertSame($expect, $expires->getExpires()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function expiresData(): array |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
[0, 0], |
27
|
|
|
[false, 0], |
28
|
|
|
['session', 0], |
29
|
|
|
['Session', 0], |
30
|
|
|
['sessioN', 0], |
31
|
|
|
['SeSsiOn', 0], |
32
|
|
|
[true, $this->currentTimestamp + 60 * 60 * 24 * 365], |
33
|
|
|
[10, $this->currentTimestamp + 10], |
34
|
|
|
[-1, $this->currentTimestamp + -1], |
35
|
|
|
['+1 year', $this->currentTimestamp + (60 * 60 * 24 * 365)], |
36
|
|
|
['-1 year', $this->currentTimestamp + (-60 * 60 * 24 * 365)], |
37
|
|
|
['+1 month', $this->currentTimestamp + (60 * 60 * 24 * 31)], |
38
|
|
|
['-1 month', $this->currentTimestamp + (-60 * 60 * 24 * 31)], |
39
|
|
|
['1 day', $this->currentTimestamp + (60 * 60 * 24)], |
40
|
|
|
['-1 day', $this->currentTimestamp + (-60 * 60 * 24)], |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testException() |
45
|
|
|
{ |
46
|
|
|
$this->expectException(Exception::class); |
47
|
|
|
new Expires('invalid string'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|