|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace CrudSys\OAuth2\Client\Test\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use CrudSys\OAuth2\Client\Entity\User; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class UserTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
private User $user; |
|
11
|
|
|
private $response; |
|
12
|
|
|
|
|
13
|
|
|
protected function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this->response = [ |
|
16
|
|
|
'id' => 'garrykasparov', |
|
17
|
|
|
'username' => 'garrykasparov', |
|
18
|
|
|
'patron' => 0, |
|
19
|
|
|
'online' => 1, |
|
20
|
|
|
'profile' => [ |
|
21
|
|
|
'country' => 'RU', |
|
22
|
|
|
'location' => 'Garik Kimovich Weinstein', |
|
23
|
|
|
'bio' => 'Russian chess grandmaster, former World Chess Champion, writer, political activist and commentator', |
|
24
|
|
|
'firstName' => 'Garry', |
|
25
|
|
|
'lastName' => 'Kasparov', |
|
26
|
|
|
'links' => 'https://twitter.com/garrykasparov' |
|
27
|
|
|
], |
|
28
|
|
|
'url' => 'https://lichess.org/@/garrykasparov', |
|
29
|
|
|
'completionRate' => '100000', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
$this->user = new User($this->response); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testToArray(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->assertIsArray($this->user->toArray()); |
|
38
|
|
|
$this->assertEquals($this->response, $this->user->toArray()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testGetId(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->assertEquals($this->response['id'], $this->user->getId()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testGetUsername(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertEquals($this->response['username'], $this->user->getUsername()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testIsPatron(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->assertFalse($this->user->isPatron()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testIsOnline(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->assertTrue($this->user->isOnline()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testGetProfile(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->assertIsArray($this->response['profile']); |
|
64
|
|
|
$this->assertEquals($this->response['profile'], $this->user->getProfile()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGetCountry(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertEquals($this->response['profile']['country'], $this->user->getCountry()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetLocation(): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->assertEquals($this->response['profile']['location'], $this->user->getLocation()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testGetBio(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->assertEquals($this->response['profile']['bio'], $this->user->getBio()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetFirstName(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->assertEquals($this->response['profile']['firstName'], $this->user->getFirstName()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testGetLastName(): void |
|
88
|
|
|
{ |
|
89
|
|
|
$this->assertEquals($this->response['profile']['lastName'], $this->user->getLastName()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testGetLinks(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->assertEquals($this->response['profile']['links'], $this->user->getLinks()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetUrl(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->assertEquals($this->response['url'], $this->user->getUrl()); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testGetCompletionRate(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->assertEquals($this->response['completionRate'], $this->user->getCompletionRate()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|