Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 8 | class UserTest extends BaseTester { |
||
|
|
|||
| 9 | |||
| 10 | /** @test */ |
||
| 11 | public function it_accepts_an_array_of_steam_ids() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @test |
||
| 23 | * @throws UnrecognizedId |
||
| 24 | */ |
||
| 25 | View Code Duplication | public function it_throws_an_exception_when_no_display_name_is_provided() |
|
| 26 | { |
||
| 27 | if (method_exists($this, 'setExpectedException')) { |
||
| 28 | $this->setExpectedException('Syntax\SteamApi\Exceptions\UnrecognizedId'); |
||
| 29 | } else { |
||
| 30 | $this->expectException('Syntax\SteamApi\Exceptions\UnrecognizedId'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $steamObject = $this->steamClient->user($this->id64)->ResolveVanityURL(); |
||
| 34 | |||
| 35 | $this->assertEquals('No match', $steamObject); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** @test |
||
| 39 | * @throws UnrecognizedId |
||
| 40 | */ |
||
| 41 | public function it_returns_no_match_from_an_invalid_display_name() |
||
| 47 | |||
| 48 | /** @test |
||
| 49 | * @throws UnrecognizedId |
||
| 50 | */ |
||
| 51 | public function it_gets_the_steam_id_from_a_display_name() |
||
| 57 | |||
| 58 | /** @test */ |
||
| 59 | public function it_gets_the_base_users_player_summary() |
||
| 67 | |||
| 68 | /** @test */ |
||
| 69 | public function it_gets_the_supplied_users_player_summary() |
||
| 79 | |||
| 80 | /** @test */ |
||
| 81 | View Code Duplication | public function it_gets_all_users_in_friend_list() |
|
| 82 | { |
||
| 83 | $friendsList = $this->steamClient->user($this->id64)->GetFriendList('all'); |
||
| 84 | |||
| 85 | $this->assertGreaterThan(0, $friendsList); |
||
| 86 | |||
| 87 | $this->checkPlayerProperties($friendsList); |
||
| 88 | $this->checkPlayerClasses($friendsList); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** @test */ |
||
| 92 | View Code Duplication | public function it_gets_friend_users_in_friend_list() |
|
| 93 | { |
||
| 94 | $friendsList = $this->steamClient->user($this->id64)->GetFriendList('friend'); |
||
| 95 | |||
| 96 | $this->assertGreaterThan(0, $friendsList); |
||
| 97 | |||
| 98 | $this->checkPlayerProperties($friendsList); |
||
| 99 | $this->checkPlayerClasses($friendsList); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** @test */ |
||
| 103 | View Code Duplication | public function it_throws_exception_to_invalid_relationship_types() |
|
| 104 | { |
||
| 105 | $expectedMessage = 'Provided relationship [nonFriend] is not valid. Please select from: all, friend'; |
||
| 106 | |||
| 107 | if (method_exists($this, 'setExpectedException')) { |
||
| 108 | $this->setExpectedException('InvalidArgumentException', $expectedMessage); |
||
| 109 | } else { |
||
| 110 | $this->expectException('InvalidArgumentException'); |
||
| 111 | $this->expectExceptionMessage($expectedMessage); |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->steamClient->user($this->id64)->GetFriendList('nonFriend'); |
||
| 115 | } |
||
| 116 | |||
| 117 | /** @test */ |
||
| 118 | public function it_gets_the_bans_for_the_base_user() |
||
| 127 | |||
| 128 | /** @test */ |
||
| 129 | public function it_gets_the_bans_for_the_supplied_user() |
||
| 140 | |||
| 141 | private function checkPlayerClasses($friendsList) |
||
| 146 | } |