Completed
Push — master ( 829fed...156410 )
by Дмитрий
04:36
created

VkTest::testGetAccessTokenFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1.037
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 6
    protected function getProvider(ClientInterface $httpClient = null)
22
    {
23 6
        $service = new \SocialConnect\Auth\Service(
24
            [
25
                'redirectUri' => 'http://localhost:8000/'
26 6
            ]
27 6
        );
28
29 6
        if ($httpClient) {
30 1
            $service->setHttpClient($httpClient);
31 1
        }
32
33 6
        return new \SocialConnect\Auth\Provider\Vk(
34 6
            $service,
35 6
            new Consumer(
36 6
                'unknown',
37
                'unkwown'
38 6
            )
39 6
        );
40
    }
41
42 1
    public function testMakeAuthUrl()
43
    {
44 1
        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 1
            'https://oauth.vk.com/authorize?client_id=unknown&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F%2Fvk%2F&response_type=code',
46 1
            $this->getProvider()->makeAuthUrl()
47 1
        );
48 1
    }
49
50
    /**
51
     * @expectedException \InvalidArgumentException
52
     * @expectedExceptionMessage Parameter $code must be a string
53
     */
54 1
    public function testGetAccessTokenFail()
55
    {
56 1
        $this->getProvider()->getAccessToken(null);
57
    }
58
59
60 1
    public function testParseTokenSuccess()
61
    {
62 1
        $expectedToken = 'XXXXXXXX';
63 1
        $expectedUserId = 123456;
64
65 1
        $accessToken = $this->getProvider()->parseToken(
66 1
            json_encode(
67
                [
68 1
                    'access_token' => $expectedToken,
69
                    'user_id' => $expectedUserId
70 1
                ]
71 1
            )
72 1
        );
73
74 1
        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...
75 1
        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...
76 1
        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...
77 1
    }
78
79 1
    public function testParseTokenNotToken()
80
    {
81 1
        $this->setExpectedException(InvalidAccessToken::class);
82
83 1
        $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...
84 1
            json_encode([])
85 1
        );
86
    }
87
88 1
    public function testParseTokenNotValidJSON()
89
    {
90 1
        $this->setExpectedException(InvalidAccessToken::class);
91
92 1
        $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...
93
            'lelelelel'
94 1
        );
95
    }
96
97 1
    public function testGetIdentitySuccess()
98
    {
99 1
        $mockedHttpClient = $this->makeIdentityClientResponse(
100
            [
101
                'response' => [
102
                    [
103 1
                        'id' => $expectedId = 12321312312312,
104 1
                        'first_name' => $expectedFirstname = 'Dmitry',
105 1
                        'last_name' => $expectedLastname = 'Patsura',
106
                    ]
107 1
                ]
108 1
            ]
109 1
        );
110
111 1
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
112 1
            new AccessToken(
113
                [
114
                    'access_token' => '123456789'
115 1
                ]
116 1
            )
117 1
        );
118
119 1
        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...
120 1
        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...
121 1
        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...
122 1
        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...
123 1
    }
124
}
125