Passed
Push — master ( a34430...be75a4 )
by Enjoys
01:35
created

CookieTest::test1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 23
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 36
rs 9.552
1
<?php
2
3
namespace Tests\Enjoys\Cookie;
4
5
use Enjoys\Cookie\Cookie;
6
use Enjoys\Cookie\Options;
7
use PHPUnit\Framework\TestCase;
8
9
10
class CookieTest extends TestCase
11
{
12
13
14
    /**
15
     * @runInSeparateProcess
16
     */
17
    public function test1()
18
    {
19
        $cookie = new Cookie(new Options());
20
21
        $cookieMock = $this->getMockBuilder(Cookie::class)->disableOriginalConstructor()->getMock();
22
        $cookieMock->expects($this->any())->method('set')->willReturnCallback(
23
            function ($key, $value) use ($cookie) {
24
                $cookie->set($key, $value, 3600);
25
                $_COOKIE[$key] = urlencode($value);
26
                return true;
27
            }
28
        );
29
30
        $cookieMock->expects($this->any())->method('setRaw')->willReturnCallback(
31
            function ($key, $value) use ($cookie) {
32
                $cookie->setRaw($key, $value, 3600);
33
                $_COOKIE[$key] = $value;
34
                return true;
35
            }
36
        );
37
38
        $cookieMock->expects($this->any())->method('delete')->willReturnCallback(
39
            function ($key) use ($cookie) {
40
                $cookie->delete($key);
41
                unset($_COOKIE[$key]);
42
            }
43
        );
44
45
        $cookieMock->setRaw('keyRaw', 'value<>');
46
        $cookieMock->set('key', 'value<>');
47
48
        $this->assertSame(true, Cookie::has('key'));
49
        $this->assertSame('value%3C%3E', Cookie::get('key'));
50
        $this->assertSame('value<>', Cookie::get('keyRaw'));
51
        $cookieMock->delete('key');
52
        $this->assertSame(false, Cookie::has('key'));
53
54
    }
55
56
}
57