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

AuthSessionTest::testNoToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 3
c 1
b 1
f 1
dl 0
loc 5
rs 10
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\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