Completed
Push — Laravel4 ( 02d48b...8c5149 )
by Travis
03:47 queued 03:02
created

UserTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 12
c 5
b 0
f 2
lcom 1
cbo 2
dl 0
loc 122
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A it_throws_an_exception_when_no_display_name_is_provided() 0 7 1
A it_returns_no_match_from_an_invalid_display_name() 0 6 1
A it_gets_the_steam_id_from_a_display_name() 0 6 1
A it_gets_the_base_users_player_summary() 0 8 1
A it_gets_the_supplied_users_player_summary() 0 10 1
A it_gets_the_bans_for_the_base_user() 0 9 1
A it_gets_the_bans_for_the_supplied_user() 0 11 1
A it_accepts_an_array_of_steam_ids() 0 9 1
A it_gets_all_users_in_friend_list() 0 9 1
A it_gets_friend_users_in_friend_list() 0 9 1
A it_throws_exception_to_invalid_relationship_types() 0 6 1
A checkPlayerClasses() 0 5 1
1
<?php
2
3
/** @group User */
4
class UserTest extends BaseTester {
5
6
    /** @test */
7
    public function it_accepts_an_array_of_steam_ids()
8
    {
9
        $steamIds = [$this->id32, $this->altId64];
10
11
        $userService = $this->steamClient->user($steamIds);
12
13
        $this->assertCount(2, $userService->getSteamId());
14
        $this->assertEquals($this->id64, $userService->getSteamId()[0]);
15
    }
16
17
	/**
18
	 * @test
19
	 */
20
    public function it_throws_an_exception_when_no_display_name_is_provided()
21
    {
22
		$this->setExpectedException('Syntax\SteamApi\Exceptions\UnrecognizedId');
23
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL();
24
25
        $this->assertEquals('No match', $steamObject);
26
    }
27
28
    /** @test */
29
    public function it_returns_no_match_from_an_invalid_display_name()
30
    {
31
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL('stygiansabyssINVALID');
32
33
        $this->assertEquals('No match', $steamObject);
34
    }
35
36
    /** @test */
37
    public function it_gets_the_steam_id_from_a_display_name()
38
    {
39
        $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL('stygiansabyss');
40
41
        $this->assertEquals($this->id64, $steamObject->id64);
42
    }
43
44
    /** @test */
45
    public function it_gets_the_base_users_player_summary()
46
    {
47
        $friendsList = $this->steamClient->user($this->id64)->GetPlayerSummaries();
48
49
        $this->assertCount(1, $friendsList);
50
        $this->checkPlayerProperties($friendsList);
51
        $this->checkPlayerClasses($friendsList);
52
    }
53
54
    /** @test */
55
    public function it_gets_the_supplied_users_player_summary()
56
    {
57
        $friendsList = $this->steamClient->user($this->id64)->GetPlayerSummaries($this->altId64);
58
59
        $this->assertCount(1, $friendsList);
60
        $this->checkPlayerProperties($friendsList);
61
        $this->checkPlayerClasses($friendsList);
62
63
        $this->assertNotEquals($friendsList[0]->steamId, $this->id64);
64
    }
65
66
    /** @test */
67
    public function it_gets_all_users_in_friend_list()
68
    {
69
        $friendsList = $this->steamClient->user($this->id64)->GetFriendList('all');
70
71
        $this->assertGreaterThan(0, $friendsList);
72
73
        $this->checkPlayerProperties($friendsList);
74
        $this->checkPlayerClasses($friendsList);
75
    }
76
77
    /** @test */
78
    public function it_gets_friend_users_in_friend_list()
79
    {
80
        $friendsList = $this->steamClient->user($this->id64)->GetFriendList('friend');
81
82
        $this->assertGreaterThan(0, $friendsList);
83
84
        $this->checkPlayerProperties($friendsList);
85
        $this->checkPlayerClasses($friendsList);
86
    }
87
88
    /** @test */
89
    public function it_throws_exception_to_invalid_relationship_types()
90
    {
91
        $this->setExpectedException('InvalidArgumentException', 'Provided relationship [nonFriend] is not valid.  Please select from: all, friend');
92
93
        $this->steamClient->user($this->id64)->GetFriendList('nonFriend');
94
    }
95
96
    /** @test */
97
    public function it_gets_the_bans_for_the_base_user()
98
    {
99
        $bans = $this->steamClient->user($this->id64)->GetPlayerBans();
100
101
        $this->assertCount(1, $bans);
102
103
        $attributes = ['SteamId', 'CommunityBanned', 'VACBanned', 'NumberOfVACBans', 'DaysSinceLastBan', 'EconomyBan'];
104
        $this->assertObjectHasAttributes($attributes, $bans[0]);
105
    }
106
107
    /** @test */
108
    public function it_gets_the_bans_for_the_supplied_user()
109
    {
110
        $bans = $this->steamClient->user($this->id64)->GetPlayerBans($this->altId64);
111
112
        $this->assertCount(1, $bans);
113
114
        $attributes = ['SteamId', 'CommunityBanned', 'VACBanned', 'NumberOfVACBans', 'DaysSinceLastBan', 'EconomyBan'];
115
        $this->assertObjectHasAttributes($attributes, $bans[0]);
116
117
        $this->assertNotEquals($bans[0]->SteamId, $this->id64);
118
    }
119
120
    private function checkPlayerClasses($friendsList)
121
    {
122
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Player', $friendsList[0]);
123
        $this->assertInstanceOf('Syntax\SteamApi\Containers\Id', $friendsList[0]->steamIds);
124
    }
125
}