Completed
Push — master ( 523fca...acca1c )
by Дмитрий
03:47
created

VkTest::testParseTokenSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.027

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 10
cp 0.7
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 1.027
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
42 1
        $accessToken = $this->getProvider()->parseToken(
43 1
            json_encode(
44
                [
45
                    'access_token' => $expectedToken
46 1
                ]
47 1
            )
48 1
        );
49
50
        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...
51
        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...
52
    }
53
54 1
    public function testParseTokenNotToken()
55
    {
56 1
        $this->setExpectedException(InvalidAccessToken::class);
57
58 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...
59 1
            json_encode([])
60 1
        );
61
    }
62
63 1
    public function testParseTokenNotValidJSON()
64
    {
65 1
        $this->setExpectedException(InvalidAccessToken::class);
66
67 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...
68
            'lelelelel'
69 1
        );
70 1
    }
71
72 1
    public function testGetIdentitySuccess()
73
    {
74 1
        $mockedHttpClient = $this->getMockBuilder(\SocialConnect\Common\Http\Client\Curl::class)
75 1
            ->disableProxyingToOriginalMethods()
76 1
            ->getMock();
77
78 1
        $response = new \SocialConnect\Common\Http\Response(
79 1
            200,
80 1
            json_encode(
81
                [
82
                    'response' => [
83 1
                        [
84 1
                            'id' => $expectedId = 12321312312312,
85 1
                            'first_name' => $expectedFirstname = 'Dmitry',
86 1
                            'last_name' => $expectedLastname = 'Patsura',
87
                        ]
88 1
                    ]
89 1
                ]
90 1
            ),
91 1
            []
92 1
        );
93
94 1
        $mockedHttpClient->expects($this->once())
95 1
            ->method('request')
96 1
            ->willReturn($response);
97
98
99 1
        $result = $this->getProvider($mockedHttpClient)->getIdentity(
100 1
            new AccessToken('unknown')
101 1
        );
102
103 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...
104 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...
105 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...
106 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...
107 1
    }
108
}
109