This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

time to make tests for steamapi

  • Loading branch information...
jung35 committed Oct 4, 2015
1 parent c61ea99 commit 2d36aa3cbba021d5d655896fdd22f75db26eb377
Showing with 13 additions and 14 deletions.
  1. +9 −12 app/Steam/SteamUser.php
  2. +4 −2 tests/Steam/SteamUserTest.php
View
@@ -30,12 +30,9 @@ public function fetch() // returns steam 64bit id
if(!$isArray) $data = [$data];
$validIds = [];
- $max = $isArray ? count($data) : 1;
- for($i = 0; $i < $max; $i++)
+ foreach($data as $value)
{
- $value = $data[$i];
-
if($this->verify32Bit($value)) $validIds[] = $this->convert32Bit($value);
elseif($this->verifyUID($value)) $validIds[] = $this->convertUID($value);
elseif($this->verifyId($value)) $validIds[] = $value;
@@ -44,7 +41,10 @@ public function fetch() // returns steam 64bit id
$validIds = $this->cleanArray($validIds);
- return $isArray ? $validIds : $validIds[0];
+ if(!isset($validIds[0])) return 'Invalid Input';
+
+ if($isArray) return $validIds;
+ return $validIds[0];
}
private function cleanArray($array)
@@ -68,7 +68,7 @@ private function checkData()
if(($isArray && count($data) == 0)
|| (!$isArray && (strlen($data) < 1 || strlen($data) > 100)))
{
- return 'Invalid or empty input';
+ return 'Invalid Input';
}
return false;
@@ -122,14 +122,12 @@ private function convertVanityURL($value)
foreach ($tmp as $key => $item)
{
if(!isset($tmp[$key + 1]) || empty($tmp[$key + 1])) break;
-
- if ($item == 'profiles')
+ elseif ($item == 'profiles')
{
$value = $tmp[$key + 1];
return $this->verifyId($value) ? $value : null;
}
-
- if ($item == 'id')
+ elseif ($item == 'id')
{
$tmp = $tmp[$key + 1];
break;
@@ -139,8 +137,7 @@ private function convertVanityURL($value)
$steamAPI = new SteamAPI($tmp);
$steamVanityUrl = $steamAPI->fetch('vanityUrl');
- if(isset($steamVanityUrl['type']) && $steamVanityUrl['type'] == 'error'
- || !isset($steamVanityUrl['response']['steamid'])) return;
+ if(!isset($steamVanityUrl['response']['steamid'])) return;
$steamid64 = (string) $steamVanityUrl['response']['steamid'];
@@ -26,7 +26,9 @@ public function test_steamuser()
public function test_steamuser_invalid()
{
- $this->assertEquals('Invalid or empty input', (new SteamUser([]))->fetch());
- $this->assertEquals('Invalid or empty input', (new SteamUser(''))->fetch());
+ $this->assertEquals('Invalid Input', (new SteamUser([]))->fetch());
+ $this->assertEquals('Invalid Input', (new SteamUser(['123iojasdfoijasdom']))->fetch());
+ $this->assertEquals('Invalid Input', (new SteamUser(''))->fetch());
+ $this->assertEquals('Invalid Input', (new SteamUser('123iojasdfoijasdom'))->fetch());
}
}

0 comments on commit 2d36aa3

Please sign in to comment.