Completed
Push — master ( fb0071...82a3a6 )
by Дмитрий
03:51
created

VkTest::testGetIdentityInternalServerError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace Test\Providers;
8
9
use SocialConnect\Auth\Provider\Exception\InvalidAccessToken;
10
use SocialConnect\Auth\Consumer;
11
use SocialConnect\OAuth2\AccessToken;
12
use SocialConnect\Common\Http\Client\ClientInterface;
13
use Test\TestCase;
14
15
class VkTest extends AbstractProviderTestCase
16
{
17
    /**
18
     * @param ClientInterface|null $httpClient
19
     * @return \SocialConnect\Auth\Provider\Vk
20
     */
21
    protected function getProvider(ClientInterface $httpClient = null)
22
    {
23
        $service = new \SocialConnect\Auth\Service(
24
            [
25
                'redirectUri' => 'http://localhost:8000/'
26
            ]
27
        );
28
29
        if ($httpClient) {
30
            $service->setHttpClient($httpClient);
31
        }
32
33
        return new \SocialConnect\Auth\Provider\Vk(
34
            $service,
35
            new Consumer(
36
                'unknown',
37
                'unkwown'
38
            )
39
        );
40
    }
41
42
    public function testMakeAuthUrl()
43
    {
44
        parent::assertSame(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testMakeAuthUrl()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
45
            'https://oauth.vk.com/authorize?client_id=unknown&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F%2Fvk%2F&response_type=code',
46
            $this->getProvider()->makeAuthUrl()
47
        );
48
    }
49
50
    /**
51
     * @expectedException \InvalidArgumentException
52
     * @expectedExceptionMessage Parameter $code must be a string
53
     */
54
    public function testGetAccessTokenFail()
55
    {
56
        $this->getProvider()->getAccessToken(null);
57
    }
58
59
60
    public function testMakeAccessTokenRequest()
61
    {
62
        $expectedCode = 'djsflkSdjflskdfjFlsd9';
63
64
        $provider = $this->getProvider();
65
66
        /** @var \SocialConnect\Common\Http\Request $request */
67
        $request = parent::callProtectedMethod(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (callProtectedMethod() instead of testMakeAccessTokenRequest()). Are you sure this is correct? If so, you might want to change this to $this->callProtectedMethod().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
68
            $provider,
69
            'makeAccessTokenRequest',
70
            [
71
                $expectedCode
72
            ]
73
        );
74
75
        parent::assertInstanceOf(\SocialConnect\Common\Http\Request::class, $request);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertInstanceOf() instead of testMakeAccessTokenRequest()). Are you sure this is correct? If so, you might want to change this to $this->assertInstanceOf().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
76
        parent::assertSame($provider->getRequestTokenUri(), $request->getUri());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testMakeAccessTokenRequest()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
77
    }
78
79
    public function testParseTokenSuccess()
80
    {
81
        $expectedToken = 'XXXXXXXX';
82
        $expectedUserId = 123456;
83
84
        $accessToken = $this->getProvider()->parseToken(
85
            json_encode(
86
                [
87
                    'access_token' => $expectedToken,
88
                    'user_id' => $expectedUserId
89
                ]
90
            )
91
        );
92
93
        parent::assertInstanceOf(AccessToken::class, $accessToken);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertInstanceOf() instead of testParseTokenSuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertInstanceOf().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
94
        parent::assertSame($expectedToken, $accessToken->getToken());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testParseTokenSuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
95
        parent::assertSame($expectedUserId, $accessToken->getUserId());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testParseTokenSuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
96
    }
97
98
    public function testParseTokenNotToken()
99
    {
100
        $this->setExpectedException(InvalidAccessToken::class);
101
102
        $accessToken = $this->getProvider()->parseToken(
0 ignored issues
show
Unused Code introduced by
$accessToken is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
103
            json_encode([])
104
        );
105
    }
106
107
    public function testParseTokenNotValidJSON()
108
    {
109
        $this->setExpectedException(InvalidAccessToken::class);
110
111
        $accessToken = $this->getProvider()->parseToken(
0 ignored issues
show
Unused Code introduced by
$accessToken is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
112
            'lelelelel'
113
        );
114
    }
115
116
    public function testGetIdentitySuccess()
117
    {
118
        $mockedHttpClient = $this->makeIdentityClientResponse(
119
            json_encode(
120
                [
121
                    'response' => [
122
                        [
123
                            'id' => $expectedId = 12321312312312,
124
                            'first_name' => $expectedFirstname = 'Dmitry',
125
                            'last_name' => $expectedLastname = 'Patsura',
126
                            'sex' => 1,
127
                        ]
128
                    ]
129
                ]
130
            )
131
        );
132
133
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
134
            new AccessToken(
135
                [
136
                    'access_token' => '123456789'
137
                ]
138
            )
139
        );
140
141
        parent::assertInstanceOf(\SocialConnect\Common\Entity\User::class, $result);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertInstanceOf() instead of testGetIdentitySuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertInstanceOf().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
142
        parent::assertSame($expectedId, $result->id);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testGetIdentitySuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
143
        parent::assertSame($expectedFirstname, $result->firstname);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testGetIdentitySuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
144
        parent::assertSame($expectedLastname, $result->lastname);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testGetIdentitySuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
145
        parent::assertSame('female', $result->sex);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testGetIdentitySuccess()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
146
    }
147
148
    /**
149
     * @expectedException \SocialConnect\Auth\Provider\Exception\InvalidResponse
150
     * @expectedExceptionMessage API response with error code
151
     */
152
    public function testGetIdentityInternalServerError()
153
    {
154
        $mockedHttpClient = $this->makeIdentityClientResponse(
155
            [],
156
            500
157
        );
158
159
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
160
            new AccessToken(
161
                [
162
                    'access_token' => '123456789'
163
                ]
164
            )
165
        );
166
    }
167
168
    /**
169
     * @expectedException \SocialConnect\Auth\Provider\Exception\InvalidResponse
170
     * @expectedExceptionMessage API response is not a valid JSON object
171
     */
172
    public function testGetIdentityNotData()
173
    {
174
        $mockedHttpClient = $this->makeIdentityClientResponse(
175
            [],
176
            200
177
        );
178
179
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
180
            new AccessToken(
181
                [
182
                    'access_token' => '123456789'
183
                ]
184
            )
185
        );
186
    }
187
}
188