OKUnitTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testDispatchUserInfo() 0 21 1
A getSettings() 0 7 1
A testGetUserInfoUri() 0 8 1
A testGetTokenUri() 0 9 1
A testGetOauthUri() 0 11 1
A testGetTokenParams() 0 14 1
1
<?php
2
namespace Mezon\SocialNetwork\Auth\Tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Mezon\SocialNetwork\Auth\Odnoklassniki;
6
7
/**
8
 *
9
 * @psalm-suppress PropertyNotSetInConstructor
10
 */
11
class OKUnitTest extends TestCase
12
{
13
14
    /**
15
     * Method returns fake settings
16
     *
17
     * @return array fake settings
18
     */
19
    protected function getSettings(): array
20
    {
21
        return ([
22
            'client_id' => 1,
23
            'client_secret' => 2,
24
            'redirect_uri' => 3,
25
            'client_public' => 4
26
        ]);
27
    }
28
29
    /**
30
     * Testing getUserInfoUri
31
     */
32
    public function testGetUserInfoUri(): void
33
    {
34
        // setup
35
        $auth = new Odnoklassniki($this->getSettings());
36
37
        // test body and assertions
38
        $this->assertStringContainsString('/api.odnoklassniki.ru/fb.do?application_key=', $auth->getUserInfoUri());
39
        $this->assertStringContainsString('?application_key=4', $auth->getUserInfoUri());
40
    }
41
42
    /**
43
     * Testing getTokenUri
44
     */
45
    public function testGetTokenUri(): void
46
    {
47
        // setup
48
        $auth = new Odnoklassniki($this->getSettings());
49
50
        // test body and assertions
51
        $this->assertStringContainsString(
52
            '/api.odnoklassniki.ru/oauth/token.do?grant_type=authorization_code&',
53
            $auth->getTokenUri());
54
    }
55
56
    /**
57
     * Testing dispatchUserInfo
58
     */
59
    public function testDispatchUserInfo(): void
60
    {
61
        // setup
62
        $auth = new Odnoklassniki($this->getSettings());
63
64
        // test body
65
        $result = $auth->dispatchUserInfo(
66
            [
67
                'uid' => '',
68
                'first_name' => '',
69
                'last_name' => '',
70
                'pic190x190' => '',
71
                'email' => ''
72
            ]);
73
74
        // assertions
75
        $this->assertArrayHasKey('id', $result, 'id was not found');
76
        $this->assertArrayHasKey('first_name', $result, 'first_name was not found');
77
        $this->assertArrayHasKey('last_name', $result, 'last_name was not found');
78
        $this->assertArrayHasKey('picture', $result, 'picture was not found');
79
        $this->assertArrayHasKey('email', $result, 'email was not found');
80
    }
81
82
    /**
83
     * Testing getTokenParams method
84
     */
85
    public function testGetTokenParams(): void
86
    {
87
        // setup
88
        $auth = new Odnoklassniki($this->getSettings());
89
90
        // test body
91
        $params = $auth->getTokenParams('123');
92
93
        // assertions
94
        $this->assertEquals(1, $params['client_id'], 'Invalid "client_id"');
95
        $this->assertEquals(2, $params['client_secret'], 'Invalid "client_secret"');
96
        $this->assertEquals(3, $params['redirect_uri'], 'Invalid "redirect_uri"');
97
        $this->assertEquals('authorization_code', $params['grant_type'], 'Invalid "grant_type"');
98
        $this->assertEquals(123, $params['code'], 'Invalid "code"');
99
    }
100
101
    /**
102
     * Testing method getOauthUri
103
     */
104
    public function testGetOauthUri(): void
105
    {
106
        // setup
107
        $auth = new Odnoklassniki($this->getSettings());
108
109
        // test body
110
        $result = $auth->getOauthUri();
111
112
        // assertions
113
        $this->assertStringContainsString('https://connect.ok.ru/', $result);
114
        $this->assertStringContainsString('?scope=VALUABLE_ACCESS;PHOTO_CONTENT&', $result);
115
    }
116
}
117