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

TokenTest::testGetUserIdentifierFromData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
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\Models\Clients\Clients;
9
use ByTIC\Hello\Tests\AbstractTest;
10
use Nip\Collections\Collection;
11
12
/**
13
 * Class TokenTest
14
 * @package ByTIC\Hello\Tests\Models\AccessTokens
15
 */
16
class TokenTest extends AbstractTest
17
{
18
19 View Code Duplication
    public function testSetIdentifier()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        /** @var Clients $tokens */
22
        $tokens = \Mockery::mock(Tokens::class)->makePartial();
23
        $tokens->shouldReceive('getFields')->andReturn(['id', 'identifier', 'secret']);
0 ignored issues
show
Documentation Bug introduced by
The method shouldReceive does not exist on object<ByTIC\Hello\Models\Clients\Clients>? 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...
24
        $tokens->shouldReceive('getPrimaryKey')->andReturn('id');
0 ignored issues
show
Documentation Bug introduced by
The method shouldReceive does not exist on object<ByTIC\Hello\Models\Clients\Clients>? 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...
25
        $tokens->shouldReceive('getModel')->andReturn(Token::class);
0 ignored issues
show
Documentation Bug introduced by
The method shouldReceive does not exist on object<ByTIC\Hello\Models\Clients\Clients>? 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...
26
27
        $token = $tokens->getNew();
28
        self::assertNull($token->getIdentifier());
29
30
        $token->setIdentifier(99);
31
        self::assertSame(99, $token->getIdentifier());
32
33
        $data = $tokens->getQueryModelData($token);
34
        self::assertArrayHasKey('identifier', $data);
35
    }
36
37
    public function testGetClient()
38
    {
39
        /** @var Tokens $tokens */
40
        $tokens = \Mockery::mock(Tokens::class)->makePartial();
41
        $tokens->shouldReceive('getPrimaryKey')->andReturn('id');
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...
42
        $tokens->shouldReceive('getModel')->andReturn(Token::class);
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...
43
44
        $clients = \Mockery::mock(Clients::class)->makePartial();
45
        $clients->shouldReceive('findByField')->withArgs([
46
            'identifier',
47
            '999999'
48
        ])->andReturn(new Collection([new Client()]));
49
        $tokens->getRelation('Client')->setWith($clients);
50
51
        $token = $tokens->getNew();
52
        $token->client_id = '999999';
53
54
        $client = $token->getClient();
55
        self::assertInstanceOf(Client::class, $client);
56
    }
57
58
    public function testGetUserIdentifierFromData()
59
    {
60
        $token = new Token();
61
        $token->writeData(['user_id' => 99]);
0 ignored issues
show
Documentation introduced by
array('user_id' => 99) is of type array<string,integer,{"user_id":"integer"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
63
        self::assertEquals(99, $token->getUserIdentifier());
64
    }
65
}
66