Skip to content

Instantly share code, notes, and snippets.

@chrisjohnson00
Created January 25, 2013 02:29
Show Gist options
  • Save chrisjohnson00/4631225 to your computer and use it in GitHub Desktop.
Save chrisjohnson00/4631225 to your computer and use it in GitHub Desktop.
Blizzard WOW Character Progression API Payload Test
public function testCharacterProgressionPayload()
{
$payload = $this->getPayloadObject($this->urlArray['CharacterProgression']);
$this->assertInternalType('object', $payload, 'Payload is not an object');
$this->assertObjectHasAttributeOfType('progression', 'object', $payload);
$progression = $payload->progression;
$this->assertObjectHasAttributeOfType('raids', 'array', $progression);
foreach ($progression->raids as $raid)
{
$this->assertInternalType('object', $raid, 'raid is not an object');
$this->assertObjectHasAttributeOfType('name', 'string', $raid);
$this->assertObjectHasAttributeOfType('normal', 'int', $raid);
$this->assertObjectHasAttributeOfType('heroic', 'int', $raid);
$this->assertObjectHasAttributeOfType('id', 'int', $raid);
$this->assertObjectHasAttributeOfType('bosses', 'array', $raid);
foreach ($raid->bosses as $boss)
{
$this->assertInternalType('object', $boss, 'boss is not an object');
$this->assertObjectHasAttributeOfType('name', 'string', $boss);
$this->assertObjectHasAttributeOfType('normalKills', 'int', $boss);
$this->assertObjectHasAttributeOfType('heroicKills', 'int', $boss);
$this->assertObjectHasAttributeOfType('id', 'int', $boss);
}
}
}
private function assertObjectHasAttributeOfType($attribute, $type, $object)
{
$this->assertObjectHasAttribute($attribute, $object, "Object does not contain $attribute attribute");
if ($type == 'double')
$this->assertTrue(gettype($object->$attribute) == 'double', "$attribute is not a $type found " . gettype($object->$attribute));
else
$this->assertInternalType($type, $object->$attribute, "$attribute is not a $type found " . gettype($object->$attribute));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment