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

started writing test. im not sure if im doing this right

  • Loading branch information...
jung35 committed Oct 4, 2015
1 parent ab66997 commit fe4762e832e51d7d16c415cedaab43942b2d3623
Showing with 92 additions and 58 deletions.
  1. +26 −38 app/Steam/Steam.php
  2. +3 −3 database/factories/ModelFactory.php
  3. +1 −0 phpunit.xml
  4. +0 −17 tests/ExampleTest.php
  5. +62 −0 tests/Steam/SteamTest.php
View
@@ -28,54 +28,42 @@ public static function setUpdate($smallId)
Cache::put("profile_$smallId", time(), self::$UPDATE_TIME / 60);
}
public static function toSmallId($steam64BitId)
public static function converter($values, $convert)
{
if(is_array($steam64BitId))
{
$smallIds = [];
foreach($steam64BitId as $key => $value)
{
$smallIds[$key] = (int) explode('.', bcsub($value,'76561197960265728'))[0];
}
$isArray = is_array($values);
$max = $isArray ? count($values) : 1;
return $smallIds;
}
$converted = [];
if(is_numeric($steam64BitId))
for($i = 0; $i < $max; $i++)
{
$steam64BitId .= '';
return (int) explode('.', bcsub($steam64BitId,'76561197960265728'))[0];
$value = $isArray ? $values[$i] : $values;
if(!is_numeric($value)) continue;
$converted[$i] = $convert($value);
}
return ['type' => 'error'];
return $isArray ? $converted : $converted[0];
}
public static function to64bit($smallId)
public static function toSmallId($steam64BitId)
{
if(is_array($smallId))
{
$steam64BitIds = [];
foreach($smallId as $key => $value)
{
$steam64BitIds[$key] = ''.explode('.', bcadd($value,'76561197960265728'))[0];
}
return $steam64BitIds;
}
return self::converter($steam64BitId, function($steam64BitId) {
return (int) explode('.', bcsub($steam64BitId, '76561197960265728'))[0];
});
}
if(is_numeric($smallId))
{
$smallId .= '';
public static function to64bit($smallId)
{
return self::converter($smallId, function($smallId) {
return ''.explode('.', bcadd($smallId,'76561197960265728'))[0];
}
return ['type' => 'error'];
});
}
public static function to32Bit($steam64BitId)
{
if(is_numeric($steam64BitId))
{
return self::converter($steam64BitId, function($steam64BitId) {
$steamIdPartOne = substr($steam64BitId, -1) % 2 == 0 ? 0 : 1;
$steamIdPartTwo = bcsub($steam64BitId, '76561197960265728');
@@ -86,16 +74,16 @@ public static function to32Bit($steam64BitId)
return "STEAM_0:$steamIdPartOne:".explode('.', $steamIdPartTwo)[0];
}
}
return ['type' => 'error'];
return;
});
}
public static function toSteam3Id($steam64BitId)
{
if(is_numeric($steam64BitId)) return 'U:1:'.self::toSmallId($steam64BitId);
return ['type' => 'error'];
return self::converter($steam64BitId, function($steam64BitId) {
return 'U:1:'.self::toSmallId($steam64BitId);
});
}
public static function imgToHTTPS($url)
@@ -46,7 +46,7 @@
/**
* VacStatus\Models\Profile
*/
$factory->define(Profile::class, function () {
$factory->define(Profile::class, function () use ($mainUser) {
return [
'small_id' => $mainUser['small_id'],
'display_name' => $mainUser['display_name'],
@@ -67,7 +67,7 @@
/**
* VacStatus\Models\User
*/
$factory->define(User::class, function () {
$factory->define(User::class, function () use ($mainUser) {
return [
'small_id' => $mainUser['small_id'],
'display_name' => $mainUser['display_name'],
@@ -107,7 +107,7 @@
/**
* VacStatus\Models\DonationLog
*/
$factory->define(DonationLog::class, function () {
$factory->define(DonationLog::class, function () use ($mainUser) {
return [
'small_id' => $mainUser['small_id'],
'status' => 'Completed',
View
@@ -18,5 +18,6 @@
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="DB_DATABASE" value="vacstatus_test"/>
</php>
</phpunit>
View
@@ -1,17 +0,0 @@
<?php
class ExampleTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$response = $this->call('GET', '/');
$this->assertEquals(200, $response->getStatusCode());
}
}
View
@@ -0,0 +1,62 @@
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use VacStatus\Steam\Steam;
class SteamTest extends TestCase
{
private $s64bitId = ['76561198020317127', '76561197993761807'];
private $s32bitId = ['STEAM_0:1:30025699', 'STEAM_0:1:16748039'];
private $smallId = [60051399, 33496079];
public function test_for_api_key()
{
dump(Steam::class);
$this->assertEquals(gettype(Steam::getAPI()), 'string');
}
public function test_if_api_key_is_real()
{
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . Steam::getAPI() . "&steamids=76561197984911659";
$client = new GuzzleHttp\Client();
try {
$request = $client->get($url, ['connect_timeout' => 0, 'timeout' => 10]);
} catch(GuzzleHttp\Exception\ClientException $e) {
$this->fail('400 level error thrown. API key was invalid');
}
$this->assertTrue(True);
}
public function test_profile_update()
{
$testId = 123;
$this->assertTrue(Steam::canUpdate($testId));
Steam::setUpdate($testId);
$this->assertFalse(Steam::canUpdate($testId));
}
public function test_small_id_conversion_from_steam_64bit_id()
{
$this->assertEquals(Steam::toSmallId($this->s64bitId[0]), $this->smallId[0]);
$this->assertEquals(Steam::toSmallId($this->s64bitId), $this->smallId);
}
public function test_steam_64bit_id_conversion_from_small_id()
{
$this->assertEquals(Steam::to64bit($this->smallId[0]), $this->s64bitId[0]);
$this->assertEquals(Steam::to64bit($this->smallId), $this->s64bitId);
}
public function test_steam_32bit_id_conversion_from_steam_64bit_id()
{
$this->assertEquals(Steam::to32bit($this->s64bitId[0]), $this->s32bitId[0]);
$this->assertEquals(Steam::to32bit($this->s64bitId), $this->s32bitId);
}
}

0 comments on commit fe4762e

Please sign in to comment.