Passed
Push — master ( 580f55...117038 )
by Enjoys
02:13
created

ExpiresTest::expiresData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 15
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 18
rs 9.7666
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