Passed
Push — master ( 436c58...98654e )
by Anton
06:21 queued 03:52
created

AuthSessionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 3
eloc 16
c 1
b 1
f 1
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testNoToken() 0 5 1
A testLogin() 0 13 1
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\Framework\Http;
13
14
use Spiral\Encrypter\EncrypterFactory;
15
use Spiral\Framework\HttpTest;
16
use Spiral\Http\Http;
17
18
class AuthSessionTest extends HttpTest
19
{
20
    public function setUp(): void
21
    {
22
        $this->app = $this->makeApp();
23
        $key = $this->app->get(EncrypterFactory::class)->generateKey();
24
25
        $this->app = $this->makeApp([
26
            'ENCRYPTER_KEY' => $key
27
        ]);
28
29
        $this->http = $this->app->get(Http::class);
30
    }
31
32
    public function testNoToken(): void
33
    {
34
        $this->assertSame(
35
            'none',
36
            (string)$this->get('/auth/token')->getBody()
37
        );
38
    }
39
40
    public function testLogin(): void
41
    {
42
        $result = $this->get('/auth/login');
43
44
        $this->assertSame('OK', (string)$result->getBody());
45
46
        $cookies = $this->fetchCookies($result->getHeader('Set-Cookie'));
47
        $this->assertTrue(isset($cookies['token']));
48
        $this->assertTrue(isset($cookies['sid']));
49
50
        $result = $this->get('/auth/token', [], [], $cookies);
51
52
        $this->assertNotSame('none', (string)$result->getBody());
53
    }
54
}
55