FacebookUnitTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 30
dl 0
loc 98
rs 10
c 2
b 1
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetUserInfoUri() 0 7 1
A testGetDesiredFields() 0 9 1
A testGetTokenUri() 0 7 1
A testDispatchUserInfo() 0 25 1
A getSettings() 0 6 1
A testGetOauthUri() 0 10 1
1
<?php
2
namespace Mezon\SocialNetwork\Auth\Tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Mezon\SocialNetwork\Auth\Facebook;
6
7
/**
8
 *
9
 * @psalm-suppress PropertyNotSetInConstructor
10
 */
11
class FacebookUnitTest 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
        ]);
26
    }
27
28
    /**
29
     * Testing getUserInfoUri
30
     */
31
    public function testGetUserInfoUri(): void
32
    {
33
        // setupp
34
        $auth = new Facebook($this->getSettings());
35
36
        // test body and assertionss
37
        $this->assertStringContainsString('/graph.facebook.com/me?', $auth->getUserInfoUri());
38
    }
39
40
    /**
41
     * Testing getTokenUri
42
     */
43
    public function testGetTokenUri(): void
44
    {
45
        // setupp
46
        $auth = new Facebook($this->getSettings());
47
48
        // test body and assertionss
49
        $this->assertStringContainsString('/graph.facebook.com/oauth/access_token?', $auth->getTokenUri());
50
    }
51
52
    /**
53
     * Testing getDesiredFields
54
     */
55
    public function testGetDesiredFields(): void
56
    {
57
        // setupp
58
        $auth = new Facebook($this->getSettings());
59
60
        // test body and assertionss
61
        $this->assertStringContainsString(
62
            'id,first_name,last_name,email,picture.width(120).height(120)',
63
            $auth->getDesiredFields());
64
    }
65
66
    /**
67
     * Testing dispatchUserInfo
68
     */
69
    public function testDispatchUserInfo(): void
70
    {
71
        // setupp
72
        $auth = new Facebook($this->getSettings());
73
74
        // test bodyy
75
        $result = $auth->dispatchUserInfo(
76
            [
77
                'id' => '',
78
                'first_name' => '',
79
                'last_name' => '',
80
                'pic190x190' => '',
81
                'picture' => [
82
                    'data' => [
83
                        'url' => 'url'
84
                    ]
85
                ]
86
            ]);
87
88
        // assertionss
89
        $this->assertArrayHasKey('id', $result, 'id was not found');
90
        $this->assertArrayHasKey('first_name', $result, 'first_name was not found');
91
        $this->assertArrayHasKey('last_name', $result, 'last_name was not found');
92
        $this->assertArrayHasKey('picture', $result, 'picture was not found');
93
        $this->assertArrayHasKey('email', $result, 'email was not found');
94
    }
95
96
    /**
97
     * Testing method getOauthUri
98
     */
99
    public function testGetOauthUri(): void
100
    {
101
        // setup
102
        $auth = new Facebook($this->getSettings());
103
104
        // test body
105
        $result = $auth->getOauthUri();
106
107
        // assertions
108
        $this->assertEquals('https://www.facebook.com/dialog/oauth?', $result);
109
    }
110
}
111