Passed
Push — master ( 056d39...c33903 )
by Gabriel
04:13
created

TokensTest::test_getQueryModelData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 22
rs 9.7333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\Hello\Tests\Models\AccessTokens;
4
5
use ByTIC\Hello\Models\AccessTokens\Token;
6
use ByTIC\Hello\Models\AccessTokens\Tokens;
7
use ByTIC\Hello\Models\Clients\Client;
8
use ByTIC\Hello\Tests\AbstractTest;
9
use ByTIC\Hello\Tests\Fixtures\Models\Users\User;
10
use Mockery\Mock;
11
use Nip\Database\Query\Condition\AndCondition;
12
use Nip\Database\Query\Select;
13
use Nip\Records\Collections\Collection;
14
15
/**
16
 * Class TokensTest
17
 * @package ByTIC\Hello\Tests\Models\AccessTokens
18
 */
19
class TokensTest extends AbstractTest
20
{
21
    public function testGetNewToken()
22
    {
23
        $manager = new Tokens();
24
        $manager->setPrimaryKey('id');
25
26
        $client = new Client();
27
        $client->setIdentifier('999');
28
29
        $token = $manager->getNewToken($client, [], '3');
30
        self::assertInstanceOf(Token::class, $token);
31
        self::assertSame($client, $token->getClient());
32
33
        self::assertEquals(
34
            ['client_id' => '999', 'user_id' => '3'],
35
            $token->toArray()
36
        );
37
    }
38
39
    public function testGetValidUserToken()
40
    {
41
        $query = new Select();
42
        /** @var Tokens $manager */
43
        $manager = \Mockery::mock(Tokens::class)->makePartial();
44
45
        $manager->shouldReceive('newQuery')->andReturn($query);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on ByTIC\Hello\Models\AccessTokens\Tokens. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $manager->/** @scrutinizer ignore-call */ 
46
                  shouldReceive('newQuery')->andReturn($query);
Loading history...
Bug introduced by
The method andReturn() does not exist on Nip\Records\Collections\Collection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $manager->shouldReceive('newQuery')->/** @scrutinizer ignore-call */ andReturn($query);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method andReturn() does not exist on ByTIC\Hello\Models\AccessTokens\Tokens. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $manager->shouldReceive('newQuery')->/** @scrutinizer ignore-call */ andReturn($query);
Loading history...
46
        $manager->shouldReceive('findByQuery')->andReturn(new Collection([new Token()]));
47
48
        $client = new Client();
49
        $client->setIdentifier('999');
50
51
        $user = new User();
52
        $user->setIdentifier('user-1');
53
54
        $tokens = $manager->getValidUserTokens($user, $client);
55
56
        self::assertInstanceOf(Collection::class, $tokens);
57
58
        $where = $query->getPart('where');
59
        self::assertInstanceOf(AndCondition::class, $where);
60
    }
61
62
    public function test_getQueryModelData()
63
    {
64
        $data = [
65
            'id' => null,
66
            'identifier' => null,
67
            'user_id' => 9,
68
            'client_id' => null,
69
            'name' => null,
70
            'scopes' => '',
71
            'revoked' => null,
72
            'expires_at' => null,
73
            'created' => null,
74
            'updated' => null
75
        ];
76
        /** @var Mock|Tokens $manager */
77
        $manager = \Mockery::mock(Tokens::class)->makePartial();
78
        $manager->setFields(array_keys($data));
79
80
        $token = new Token();
81
        $token->user_id = 9;
82
83
        self::assertSame($data, $manager->getQueryModelData($token));
84
    }
85
}
86