Passed
Push — master ( 117038...a34430 )
by Enjoys
01:48
created

OptionsTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 39
c 1
b 0
f 1
dl 0
loc 72
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetDomain() 0 7 1
A testSetPath() 0 6 1
A testSetSecure() 0 6 1
A testSetHttponly() 0 6 1
A testGetOptionsWithAddedCustomOptions() 0 20 1
A testSetExpires() 0 6 1
A testSetSameSite() 0 6 1
1
<?php
2
3
namespace Tests\Enjoys\Cookie;
4
5
use Enjoys\Cookie\Options;
6
use PHPUnit\Framework\TestCase;
7
8
class OptionsTest extends TestCase
9
{
10
11
    public function testSetHttponly()
12
    {
13
        $options = new Options();
14
        $this->assertSame(false, $options->getOptions()['httponly']);
15
        $options->setHttponly(true);
16
        $this->assertSame(true, $options->getOptions()['httponly']);
17
    }
18
19
    public function testSetDomain()
20
    {
21
        $options = new Options();
22
        $options->setDomain(false);
23
        $this->assertSame(false, $options->getOptions()['domain']);
24
        $options->setDomain('domain.com');
25
        $this->assertSame('domain.com', $options->getOptions()['domain']);
26
    }
27
28
    public function testSetSameSite()
29
    {
30
        $options = new Options();
31
        $this->assertArrayNotHasKey('samesite', $options->getOptions());
32
        $options->setSameSite('Lax');
33
        $this->assertSame('Lax', $options->getOptions()['samesite']);
34
    }
35
36
    public function testSetPath()
37
    {
38
        $options = new Options();
39
        $this->assertSame('', $options->getOptions()['path']);
40
        $options->setPath('/');
41
        $this->assertSame('/', $options->getOptions()['path']);
42
    }
43
44
    public function testSetSecure()
45
    {
46
        $options = new Options();
47
        $this->assertSame(false, $options->getOptions()['secure']);
48
        $options->setSecure(true);
49
        $this->assertSame(true, $options->getOptions()['secure']);
50
    }
51
52
    public function testSetExpires()
53
    {
54
        $options = new Options();
55
        $this->assertSame(-1, $options->getOptions()['expires']);
56
        $options->setExpires(100500);
57
        $this->assertSame(100500, $options->getOptions()['expires']);
58
    }
59
60
    public function testGetOptionsWithAddedCustomOptions()
61
    {
62
        $options = new Options();
63
        $options->setSecure(true);
64
        $this->assertSame(false, $options->getOptions(['secure' => false])['secure']);
65
66
        $options->setPath('/');
67
        $this->assertSame('/path', $options->getOptions(['path' => '/path'])['path']);
68
69
        $options->setHttponly(true);
70
        $this->assertSame(false, $options->getOptions(['httponly' => false])['httponly']);
71
72
        $options->setSameSite('Strict');
73
        $this->assertSame('Lax', $options->getOptions(['samesite' => 'Lax'])['samesite']);
74
75
        $options->setDomain(false);
76
        $this->assertSame('example.com', $options->getOptions(['domain' => 'example.com'])['domain']);
77
78
        $options->setExpires(100500);
79
        $this->assertSame(100500, $options->getOptions(['expires' => 0])['expires']);
80
    }
81
82
}
83