Passed
Push — master ( 974680...fc5316 )
by Kirill
03:59
created

ConfigTest::testCookieDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
rs 9.9
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Cookies;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Cookies\Config\CookiesConfig;
16
use Laminas\Diactoros\Uri;
17
18
class ConfigTest extends TestCase
19
{
20
    public function testCookies(): void
21
    {
22
        $c = new CookiesConfig([
23
            'domain'   => '.%s',
24
            'method'   => CookiesConfig::COOKIE_ENCRYPT,
25
            'excluded' => ['PHPSESSID', 'csrf-token']
26
27
        ]);
28
29
        $this->assertSame(CookiesConfig::COOKIE_ENCRYPT, $c->getProtectionMethod());
30
        $this->assertSame(['PHPSESSID', 'csrf-token'], $c->getExcludedCookies());
31
    }
32
33
    public function testCookieDomain(): void
34
    {
35
        $c = new CookiesConfig([
36
            'domain' => '.%s',
37
        ]);
38
39
        $this->assertSame('.domain.com', $c->resolveDomain(new Uri('http://domain.com/')));
40
        $this->assertSame('.domain.com', $c->resolveDomain(new Uri('https://domain.com/')));
41
        $this->assertSame('.domain.com', $c->resolveDomain(new Uri('https://domain.com:9090/')));
42
        $this->assertSame(null, $c->resolveDomain(new Uri('/')));
43
        $this->assertSame('localhost', $c->resolveDomain(new Uri('localhost:9090/')));
44
45
        $this->assertSame('192.169.1.10', $c->resolveDomain(new Uri('http://192.169.1.10:8080/')));
46
47
        $c = new CookiesConfig([
48
            'domain' => '.doo.com',
49
        ]);
50
51
        $this->assertSame('.doo.com', $c->resolveDomain(new Uri('http://domain.com/')));
52
    }
53
}
54