Skip to content

Commit b410fdf

Browse files
committed
fix system test
1 parent eed5a6b commit b410fdf

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/Entities/Profile.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ public function addBadge(Badge $badge)
133133
public function getCounts()
134134
{
135135
return array(
136-
'habbo' => count($this->habbo),
137-
'badges' => count($this->badges),
138-
'friends' => count($this->friends),
139-
'groups' => count($this->groups),
140-
'rooms' => count($this->rooms),
136+
'habbo' => self::safeCount($this->habbo),
137+
'badges' => self::safeCount($this->badges),
138+
'friends' => self::safeCount($this->friends),
139+
'groups' => self::safeCount($this->groups),
140+
'rooms' => self::safeCount($this->rooms),
141141
);
142142
}
143+
144+
private function safeCount($value)
145+
{
146+
return is_countable($value) ? count($value) : 0;
147+
}
143148
}
144149

tests/SystemTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function setUpBeforeClass(): void
2222
self::$api = new HabboAPI(self::$parser);
2323
}
2424

25-
public function testTheSystem()
25+
public function testTheSystem(): void
2626
{
2727
// Don't run system tests on Travis
2828
if (getenv('TRAVIS') == "true") {
@@ -59,19 +59,17 @@ public function testTheSystem()
5959
$profile = self::$api->getProfile('hhus-e6d805c82fcd7f4717f4bff5f9f437ae');
6060

6161
// Test a badge
62+
$badge = null;
6263
$badges = $profile->getBadges();
63-
$badge = $badges[0];
64+
foreach ($badges as $b) {
65+
if ($b->getCode() == "ACH_RespectEarned1") {
66+
$badge = $b;
67+
}
68+
}
6469
$this->assertEquals("ACH_RespectEarned1", $badge->getCode());
65-
$this->assertEquals("10% Respected Habbo I", $badge->getName());
70+
$this->assertEquals("Respected Habbo I", $badge->getName());
6671
$this->assertEquals("For earning respect 1 time.", $badge->getDescription());
6772

68-
// Test a friend
69-
$friends = $profile->getFriends();
70-
$friend = $friends[0];
71-
$this->assertEquals('hhus-fa1ff34dd0562488af72aef00f958e0e', $friend->getId());
72-
$this->assertEquals('Snupdapup', $friend->getHabboName());
73-
$this->assertEquals('hr-540-34.hd-600-8.ch-884-76.lg-3216-1408.sh-730-1408.he-3274-1408.ca-1802', $friend->getFigureString());
74-
7573
// Test a group
7674
$groups = $profile->getGroups();
7775
$group = $groups[0];
@@ -100,7 +98,7 @@ public function testTheSystem()
10098
$counts = $profile->getCounts();
10199
$this->assertEquals(1, $counts['habbo']);
102100
$this->assertEquals(15, $counts['badges']);
103-
$this->assertEquals(1, $counts['friends']);
101+
$this->assertEquals(0, $counts['friends']); // Habbo deleted my only friend! :(
104102
$this->assertEquals(1, $counts['groups']);
105103
$this->assertEquals(2, $counts['rooms']);
106104

0 commit comments

Comments
 (0)