Passed
Push — master ( 27dd3a...31fea7 )
by Alex
06:49 queued 02:55
created

FacebookUnitTest   A

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
class FacebookUnitTest extends TestCase
8
{
9
10
    /**
11
     * Method returns fake settings
12
     *
13
     * @return array fake settings
14
     */
15
    protected function getSettings(): array
16
    {
17
        return ([
18
            'client_id' => 1,
19
            'client_secret' => 2,
20
            'redirect_uri' => 3
21
        ]);
22
    }
23
24
    /**
25
     * Testing getUserInfoUri
26
     */
27
    public function testGetUserInfoUri()
28
    {
29
        // setupp
30
        $auth = new Facebook($this->getSettings());
31
32
        // test body and assertionss
33
        $this->assertStringContainsString('/graph.facebook.com/me?', $auth->getUserInfoUri());
34
    }
35
36
    /**
37
     * Testing getTokenUri
38
     */
39
    public function testGetTokenUri()
40
    {
41
        // setupp
42
        $auth = new Facebook($this->getSettings());
43
44
        // test body and assertionss
45
        $this->assertStringContainsString('/graph.facebook.com/oauth/access_token?', $auth->getTokenUri());
46
    }
47
48
    /**
49
     * Testing getDesiredFields
50
     */
51
    public function testGetDesiredFields()
52
    {
53
        // setupp
54
        $auth = new Facebook($this->getSettings());
55
56
        // test body and assertionss
57
        $this->assertStringContainsString(
58
            'id,first_name,last_name,email,picture.width(120).height(120)',
59
            $auth->getDesiredFields());
60
    }
61
62
    /**
63
     * Testing dispatchUserInfo
64
     */
65
    public function testDispatchUserInfo()
66
    {
67
        // setupp
68
        $auth = new Facebook($this->getSettings());
69
70
        // test bodyy
71
        $result = $auth->dispatchUserInfo(
72
            [
73
                'id' => '',
74
                'first_name' => '',
75
                'last_name' => '',
76
                'pic190x190' => '',
77
                'picture' => [
78
                    'data' => [
79
                        'url' => 'url'
80
                    ]
81
                ]
82
            ]);
83
84
        // assertionss
85
        $this->assertArrayHasKey('id', $result, 'id was not found');
86
        $this->assertArrayHasKey('first_name', $result, 'first_name was not found');
87
        $this->assertArrayHasKey('last_name', $result, 'last_name was not found');
88
        $this->assertArrayHasKey('picture', $result, 'picture was not found');
89
        $this->assertArrayHasKey('email', $result, 'email was not found');
90
    }
91
92
    /**
93
     * Testing method getOauthUri
94
     */
95
    public function testGetOauthUri(): void
96
    {
97
        // setup
98
        $auth = new Facebook($this->getSettings());
99
100
        // test body
101
        $result = $auth->getOauthUri();
102
103
        // assertions
104
        $this->assertEquals('https://www.facebook.com/dialog/oauth?', $result);
105
    }
106
}
107