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

VkTest::testParseTokenNotValidJSON()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.008

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1.008
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 5
    protected function getProvider(ClientInterface $httpClient = null)
22
    {
23 5
        $service = new \SocialConnect\Auth\Service(
24
            [
25
                'redirectUri' => 'http://localhost:8000/'
26 5
            ]
27 5
        );
28
29 5
        if ($httpClient) {
30 1
            $service->setHttpClient($httpClient);
31 1
        }
32
33 5
        return new \SocialConnect\Auth\Provider\Vk(
34 5
            $service,
35 5
            new Consumer(
36 5
                'unknown',
37
                'unkwown'
38 5
            )
39 5
        );
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 1
    public function testParseTokenSuccess()
51
    {
52 1
        $expectedToken = 'XXXXXXXX';
53 1
        $expectedUserId = 123456;
54
55 1
        $accessToken = $this->getProvider()->parseToken(
56 1
            json_encode(
57
                [
58 1
                    'access_token' => $expectedToken,
59
                    'user_id' => $expectedUserId
60 1
                ]
61 1
            )
62 1
        );
63
64 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...
65 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...
66 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...
67 1
    }
68
69 1
    public function testParseTokenNotToken()
70
    {
71 1
        $this->setExpectedException(InvalidAccessToken::class);
72
73 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...
74 1
            json_encode([])
75 1
        );
76
    }
77
78 1
    public function testParseTokenNotValidJSON()
79
    {
80 1
        $this->setExpectedException(InvalidAccessToken::class);
81
82 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...
83
            'lelelelel'
84 1
        );
85
    }
86
87 1
    public function testGetIdentitySuccess()
88
    {
89 1
        $mockedHttpClient = $this->makeIdentityClientResponse(
90
            [
91
                'response' => [
92
                    [
93 1
                        'id' => $expectedId = 12321312312312,
94 1
                        'first_name' => $expectedFirstname = 'Dmitry',
95 1
                        'last_name' => $expectedLastname = 'Patsura',
96
                    ]
97 1
                ]
98 1
            ]
99 1
        );
100
101 1
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
102 1
            new AccessToken(
103
                [
104
                    'access_token' => '123456789'
105 1
                ]
106 1
            )
107 1
        );
108
109 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...
110 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...
111 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...
112 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...
113 1
    }
114
}
115