Completed
Push — master ( acca1c...3f7868 )
by Дмитрий
03:40
created

VkTest::testParseTokenSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
crap 1
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 TestCase
16
{
17
    /**
18
     * @param ClientInterface|null $httpClient
19
     * @return \SocialConnect\Auth\Provider\Vk
20
     */
21 4
    protected function getProvider(ClientInterface $httpClient = null)
22
    {
23 4
        $service = new \SocialConnect\Auth\Service([]);
24
25 4
        if ($httpClient) {
26 1
            $service->setHttpClient($httpClient);
27 1
        }
28
29 4
        return new \SocialConnect\Auth\Provider\Vk(
30 4
            $service,
31 4
            new Consumer(
32 4
                'unknown',
33
                'unkwown'
34 4
            )
35 4
        );
36
    }
37
38 1
    public function testParseTokenSuccess()
39
    {
40 1
        $expectedToken = 'XXXXXXXX';
41 1
        $expectedUserId = 123456;
42
43 1
        $accessToken = $this->getProvider()->parseToken(
44 1
            json_encode(
45
                [
46 1
                    'access_token' => $expectedToken,
47
                    'user_id' => $expectedUserId
48 1
                ]
49 1
            )
50 1
        );
51
52 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...
53 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...
54 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...
55 1
    }
56
57 1
    public function testParseTokenNotToken()
58 1
    {
59 1
        $this->setExpectedException(InvalidAccessToken::class);
60
61 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...
62 1
            json_encode([])
63 1
        );
64
    }
65
66 1
    public function testParseTokenNotValidJSON()
67
    {
68 1
        $this->setExpectedException(InvalidAccessToken::class);
69
70 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...
71
            'lelelelel'
72 1
        );
73
    }
74
75 1
    public function testGetIdentitySuccess()
76
    {
77 1
        $mockedHttpClient = $this->getMockBuilder(\SocialConnect\Common\Http\Client\Curl::class)
78 1
            ->disableProxyingToOriginalMethods()
79 1
            ->getMock();
80
81 1
        $response = new \SocialConnect\Common\Http\Response(
82 1
            200,
83 1
            json_encode(
84
                [
85
                    'response' => [
86
                        [
87 1
                            'id' => $expectedId = 12321312312312,
88 1
                            'first_name' => $expectedFirstname = 'Dmitry',
89 1
                            'last_name' => $expectedLastname = 'Patsura',
90
                        ]
91 1
                    ]
92 1
                ]
93 1
            ),
94 1
            []
95 1
        );
96
97 1
        $mockedHttpClient->expects($this->once())
98 1
            ->method('request')
99 1
            ->willReturn($response);
100
101
102 1
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
103 1
            new AccessToken('unknown')
104 1
        );
105
106 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...
107 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...
108 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...
109 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...
110 1
    }
111
}
112