Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

TokensTest::testGetNewToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47
        $manager->shouldReceive('findByQuery')->andReturn(new Collection([new Token()]));
0 ignored issues
show
Documentation Bug introduced by
The method shouldReceive does not exist on object<ByTIC\Hello\Models\AccessTokens\Tokens>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
49
        $client = new Client();
50
        $client->setIdentifier('999');
51
52
        $user = new User();
53
        $user->setIdentifier('user-1');
54
55
        $tokens = $manager->getValidUserTokens($user, $client);
56
57
        self::assertInstanceOf(Collection::class, $tokens);
58
59
        $where = $query->getPart('where');
60
        self::assertInstanceOf(AndCondition::class, $where);
61
    }
62
}
63