Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added in PHPUnit tests

  • Loading branch information...
commit 210f1475580ce23e2addf27d2fb4ed7878e67cb6 1 parent 119f9d7
@ameerkat authored
Showing with 108 additions and 3 deletions.
  1. +106 −0 SC2RanksTest.php
  2. +1 −2  readme.md
  3. +1 −1  sc2ranks.php
View
106 SC2RanksTest.php
@@ -0,0 +1,106 @@
+<?php
+require('sc2ranks.php');
+
+$request = new sc2ranks_request("github.com/ameerkat/sc2ranks-php");
+
+class SC2RanksTest extends PHPUnit_Framework_TestCase
+{
+ /*
+ public function testGetCharacterData()
+ {
+ global $request;
+ $data = $request->get_character_data("meerkat", 678);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ // We are assuming this does work
+ $this->assertEquals($request->last_response()->name, "meerkat");
+ $this->assertFalse(isset($request->last_response()->error));
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+ $data = $request->get_character_data("HuK", 530);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ // We are assuming this doesn't work
+ $this->assertObjectHasAttribute('error', $request->last_response());
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+ // Check that the response get's cleared
+ $data = $request->get_character_data("meerkat", 678);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ // We are assuming this does work
+ $this->assertFalse(isset($request->last_response()->error));
+ $this->assertEquals($request->last_response()->name, "meerkat");
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+
+ // We are assuming this doesn't work
+ $data = $request->get_character_data("", 0);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ $this->assertObjectHasAttribute('error', $request->last_response());
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+ $data = $request->get_character_data("", -1);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ $this->assertObjectHasAttribute('error', $request->last_response());
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+
+ $data = $request->get_character_data("meerkat", 678);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ // We are assuming this does work
+ $this->assertFalse(isset($request->last_response()->error));
+ $this->assertEquals($request->last_response()->name, "meerkat");
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+
+ // THIS BREAKS THE PROGRAM
+ // TODO Fix this
+ // $data = $request->get_character_data("¾È³çÇϼ¼¿ä", 0);
+ // $this->assertTrue($request != null);
+ // $this->assertTrue($data != null);
+ // $this->assertObjectHasAttribute('error', $request->last_response());
+
+ $data = $request->get_character_data("_asd, fff%\ okay", 0);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ $this->assertObjectHasAttribute('error', $request->last_response());
+ if($request->is_json_last_error_enabled())
+ $this->assertNull($request->json_last_error());
+ }
+ */
+
+ public function testGetBracketData(){
+ global $request;
+ $data = $request->get_character_data("meerkat", 678);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ $record = $request->get_bracket_data();
+ $this->assertTrue($record != null);
+ $this->assertObjectHasAttribute('division', $record);
+ $this->assertObjectHasAttribute('points', $record);
+ $this->assertObjectHasAttribute('division_rank', $record);
+ $this->assertObjectHasAttribute('ratio', $record);
+ $this->assertObjectHasAttribute('fav_race', $record);
+ $this->assertObjectHasAttribute('league', $record);
+ $this->assertObjectHasAttribute('wins', $record);
+ $this->assertObjectHasAttribute('world_rank', $record);
+ $this->assertObjectHasAttribute('losses', $record);
+ $this->assertObjectHasAttribute('updated_at', $record);
+ $this->assertObjectHasAttribute('is_random', $record);
+ $this->assertObjectHasAttribute('bracket', $record);
+ $this->assertObjectHasAttribute('region_rank', $record);
+
+ global $request;
+ $data = $request->get_character_data("HuK", 530);
+ $this->assertTrue($request != null);
+ $this->assertTrue($data != null);
+ $this->assertObjectHasAttribute('error', $request->last_response());
+ $record = $request->get_bracket_data();
+ $this->assertNull($record);
+ }
+}
+?>
View
3  readme.md
@@ -22,9 +22,8 @@ record, defaulting to the 1v1 record of the last requested character.
$request->get_bracket_data();
## TODO
+* Add documentation for the new merged functions
* Add support for batch requests
* Add other helper functions for processing returned data
* Add documentation somewhere for the returned object structure
-* Add link to API site, other API's
-* Licensing
* Unit Tests w/phpUnit
View
2  sc2ranks.php
@@ -4,7 +4,7 @@
* requests and pulling data back from the sc2ranks.com API. Uses the json
* interface and the built in PHP json deserializer.
* @author Ameer Ayoub <ameer.ayoub@gmail.com>
- * @version 0.2
+ * @version 0.3.1
* @package sc2ranks
*/
Please sign in to comment.
Something went wrong with that request. Please try again.