Passed
Push — master ( 67aa31...d47bdf )
by Kirill
03:20
created

AuthContextTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 26
c 1
b 0
f 0
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testNull() 0 9 1
A testTokenButNoActor() 0 8 1
A testClosed() 0 15 1
A testActor() 0 8 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\Tests\Auth;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Auth\AuthContext;
16
use Spiral\Auth\TokenInterface;
17
18
class AuthContextTest extends TestCase
19
{
20
    public function testNull(): void
21
    {
22
        $context = new AuthContext(new TestProvider());
23
24
        $this->assertNull($context->getToken());
25
        $this->assertNull($context->getActor());
26
        $this->assertNull($context->getTransport());
27
28
        $this->assertFalse($context->isClosed());
29
    }
30
31
    public function testTokenButNoActor(): void
32
    {
33
        $context = new AuthContext(new TestProvider());
34
        $context->start(new TestToken('1', ['ok' => false]), 'cookie');
35
36
        $this->assertInstanceOf(TokenInterface::class, $context->getToken());
37
        $this->assertNull($context->getActor());
38
        $this->assertSame('cookie', $context->getTransport());
39
    }
40
41
    public function testActor(): void
42
    {
43
        $context = new AuthContext(new TestProvider());
44
        $context->start(new TestToken('1', ['ok' => true]), 'cookie');
45
46
        $this->assertInstanceOf(TokenInterface::class, $context->getToken());
47
        $this->assertInstanceOf(\stdClass::class, $context->getActor());
48
        $this->assertSame('cookie', $context->getTransport());
49
    }
50
51
52
    public function testClosed(): void
53
    {
54
        $context = new AuthContext(new TestProvider());
55
        $context->start(new TestToken('1', ['ok' => true]), 'cookie');
56
57
        $this->assertInstanceOf(TokenInterface::class, $context->getToken());
58
        $this->assertInstanceOf(\stdClass::class, $context->getActor());
59
        $this->assertSame('cookie', $context->getTransport());
60
61
        $context->close();
62
63
        $this->assertInstanceOf(TokenInterface::class, $context->getToken());
64
        $this->assertNull($context->getActor());
65
        $this->assertSame('cookie', $context->getTransport());
66
        $this->assertTrue($context->isClosed());
67
    }
68
}
69