ClientHasGrantsTraitTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 6
eloc 33
c 4
b 2
f 1
dl 0
loc 74
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A dataInitFromDB() 0 6 1
A testNewClientGrants() 0 4 1
A testGrantsSave() 0 13 1
A testHasGrant() 0 10 1
A testInitFromDB() 0 6 1
A testAddGrants() 0 14 1
1
<?php
2
3
namespace ByTIC\Hello\Tests\Models\Clients\Traits;
4
5
use ByTIC\Hello\Models\Clients\Client;
6
use ByTIC\Hello\Models\Clients\Clients;
7
use ByTIC\Hello\Tests\AbstractTest;
8
use ByTIC\Hello\Utility\GrantsHelper;
9
10
/**
11
 * Class ClientHasGrantsTraitTest
12
 * @package ByTIC\Hello\Tests\Models\Clients\Traits
13
 */
14
class ClientHasGrantsTraitTest extends AbstractTest
15
{
16
    public function testNewClientGrants()
17
    {
18
        $client = new Client();
19
        self::assertSame([], $client->getGrants());
20
    }
21
22
    public function testAddGrants()
23
    {
24
        $client = new Client();
25
26
        $client->addGrants(GrantsHelper::GRANT_TYPE_EXTENSIONS);
27
        self::assertSame([GrantsHelper::GRANT_TYPE_EXTENSIONS], $client->getGrants());
28
29
        $client->addGrants(GrantsHelper::GRANT_TYPE_EXTENSIONS);
30
        self::assertSame([GrantsHelper::GRANT_TYPE_EXTENSIONS], $client->getGrants());
31
32
        $client->addGrants(GrantsHelper::GRANT_TYPE_AUTH_CODE);
33
        self::assertSame(
34
            [GrantsHelper::GRANT_TYPE_EXTENSIONS, GrantsHelper::GRANT_TYPE_AUTH_CODE],
35
            $client->getGrants()
36
        );
37
    }
38
39
    public function testHasGrant()
40
    {
41
        $client = new Client();
42
        self::assertFalse($client->hasGrant(GrantsHelper::GRANT_TYPE_AUTH_CODE));
43
44
        $client->addGrants(GrantsHelper::GRANT_TYPE_EXTENSIONS);
45
        self::assertFalse($client->hasGrant(GrantsHelper::GRANT_TYPE_AUTH_CODE));
46
47
        $client->addGrants(GrantsHelper::GRANT_TYPE_AUTH_CODE);
48
        self::assertTrue($client->hasGrant(GrantsHelper::GRANT_TYPE_AUTH_CODE));
49
    }
50
51
    public function testGrantsSave()
52
    {
53
        /** @var Clients $clients */
54
        $clients = \Mockery::mock(Clients::class)->makePartial();
55
        $clients->shouldReceive('getFields')->andReturn(['id', 'identifier', 'grant_types']);
0 ignored issues
show
Bug introduced by
The method andReturn() does not exist on ByTIC\Hello\Models\Clients\Clients. 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

55
        $clients->shouldReceive('getFields')->/** @scrutinizer ignore-call */ andReturn(['id', 'identifier', 'grant_types']);
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

55
        $clients->shouldReceive('getFields')->/** @scrutinizer ignore-call */ andReturn(['id', 'identifier', 'grant_types']);

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 shouldReceive() does not exist on ByTIC\Hello\Models\Clients\Clients. 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

55
        $clients->/** @scrutinizer ignore-call */ 
56
                  shouldReceive('getFields')->andReturn(['id', 'identifier', 'grant_types']);
Loading history...
56
        $clients->shouldReceive('getPrimaryKey')->andReturn('id');
57
        $clients->shouldReceive('getModel')->andReturn(Client::class);
58
59
        $client = $clients->getNew();
60
        $client->addGrants([GrantsHelper::GRANT_TYPE_PERSONAL_ACCESS, GrantsHelper::GRANT_TYPE_AUTH_CODE]);
61
62
        $data = $clients->getQueryModelData($client);
63
        self::assertArrayHasKey('grant_types', $data);
64
    }
65
66
    /**
67
     * @dataProvider dataInitFromDB()
68
     * @param $grantDb
69
     * @param $grantArray
70
     */
71
    public function testInitFromDB($grantDb, $grantArray)
72
    {
73
        $client = new Client();
74
        $client->writeData(['id' => 9, 'grant_types' => $grantDb]);
75
76
        self::assertSame($grantArray, $client->getGrants());
77
    }
78
79
    /**
80
     * @return array
81
     */
82
    public static function dataInitFromDB()
83
    {
84
        return [
85
            ['', []],
86
            ['personal_access', ['personal_access']],
87
            ['personal_access,authorization_code', ['personal_access', 'authorization_code']],
88
        ];
89
    }
90
}
91