Skip to content

Commit

Permalink
CurrentGame methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlbauer committed Jan 30, 2015
1 parent e75db38 commit 9b15b4c
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 1 deletion.
83 changes: 82 additions & 1 deletion src/LeagueWrap/Dto/CurrentGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,86 @@

class CurrentGame extends AbstractDto
{
// TODO implement subclasses
/**
* Set up the information about this game.
*
* @param array $info
*/
public function __construct(array $info)
{
// set bans
if ( ! isset($info['bannedChampions']))
{
// no bans in this game
$info['bannedChampions'] = [];
}
$rawBans = $info['bannedChampions'];
$bans = [];
foreach ($rawBans as $value)
{
$ban = new Ban($value);
$bans[$ban->pickTurn] = $ban;
}
$info['bannedChampions'] = $bans;

// set observer
if(isset($info['observers']))
$info['observers'] = new Observer($info['observers']);

// set participants
if ( ! isset($info['participants']))
{
$info['participants'] = [];
}
$rawParticipants = $info['participants'];
$participants = [];
foreach ($rawParticipants as $value)
{
$participant = new CurrentGameParticipant($value);
$participants[$participant->summonerId] = $participant;
}
$info['participants'] = $participants;

parent::__construct($info);
}

/**
* get a ban from the current game
* @param $pickTurn
* @return \LeagueWrap\Dto\Ban
*/
public function ban($pickTurn)
{
if ( ! isset($this->info['bannedChampions']))
{
// no bans
return null;
}
$bans = $this->info['bannedChampions'];
if (isset($bans[$pickTurn]))
{
return $bans[$pickTurn];
}
return null;
}

/**
* @param $participantId get a participant by its summoner id
* @return \LeagueWrap\Dto\CurrentGameParticipant
*/
public function participant($summonerId)
{
if ( ! isset($this->info['participants']))
{
// no players
return null;
}
$participant = $this->info['participants'];
if (isset($participant[$summonerId]))
{
return $participant[$summonerId];
}
return null;
}

}
84 changes: 84 additions & 0 deletions src/LeagueWrap/Dto/CurrentGameParticipant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace LeagueWrap\Dto;

/**
* participant of a current game
* @package LeagueWrap\Dto
*/
class CurrentGameParticipant extends AbstractDto {
use ImportStaticTrait;

protected $staticFields = [
'championId' => 'champion',
'spell1Id' => 'summonerSpell',
'spell2Id' => 'summonerSpell',
];

/**
* Set up the information about this Participant.
*
* @param array $info
*/
public function __construct(array $info)
{
// player masteries
if(isset($info['masteries']))
{
$rawMasteries = $info['masteries'];
$masteries = [];
foreach($rawMasteries as $m)
{
$mastery = new Mastery($m);
$masteries[$mastery->masteryId] = $mastery;
}
$info['masteries'] = $masteries;
}

// player runes
if(isset($info['runes']))
{
$rawRunes = $info['runes'];
$runes = [];
foreach($rawRunes as $r)
{
$rune = new Rune($r);
$runes[$rune->runeId] = $rune;
}
$info['runes'] = $runes;
}

parent::__construct($info);
}

/**
* @param $masteryId
* @return null || \Leaguewrap\Dto\Mastery
*/
public function mastery($masteryId)
{
if(!isset($this->info['masteries']))
return null;

$masteries = $this->masteries;
if(!isset($masteries[$masteryId]))
return null;
return $masteries[$masteryId];
}

/**
* @param $runeId
* @return null || \Leaguewrap\Dto\Rune
*/
public function rune($runeId)
{
if(!isset($this->info['runes']))
return null;

$runes = $this->runes;
if(!isset($runes[$runeId]))
return null;
return $runes[$runeId];
}

}
11 changes: 11 additions & 0 deletions src/LeagueWrap/Dto/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* Observerinformation for a current game
*/
namespace LeagueWrap\Dto;


class Observer extends AbstractDto {

}
98 changes: 98 additions & 0 deletions tests/Api/CurrentGameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,102 @@ public function testCurrentGame()
$game = $api->currentGame()->currentGame(30447079);
$this->assertTrue($game instanceof LeagueWrap\Dto\CurrentGame);
}

public function testCurrentGameGetBan()
{
$this->client->shouldReceive('baseUrl')
->once();
$this->client->shouldReceive('request')
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [
'api_key' => 'key',
])->once()
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json'));

$api = new Api('key', $this->client);
$api->setRegion('euw');
$game = $api->currentGame()->currentGame(30447079);

$ban = $game->ban(1);
$this->assertTrue($ban instanceof \LeagueWrap\Dto\Ban);
$this->assertTrue($ban->teamId == 100);
$this->assertTrue($ban->championId == 59);

$noBan = $game->ban(900);
$this->assertTrue(is_null($noBan));
}

public function testCurrentGameObserver()
{
$this->client->shouldReceive('baseUrl')
->once();
$this->client->shouldReceive('request')
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [
'api_key' => 'key',
])->once()
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json'));

$api = new Api('key', $this->client);
$api->setRegion('euw');
$game = $api->currentGame()->currentGame(30447079);

$this->assertTrue($game->observers instanceof \LeagueWrap\Dto\Observer);
$this->assertTrue($game->observers->encryptionKey == "02PHNRQw/YzBA35fF/LMVao8ui8A7pnz");
}

public function testCurrentGameParticipant()
{
$this->client->shouldReceive('baseUrl')
->once();
$this->client->shouldReceive('request')
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [
'api_key' => 'key',
])->once()
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json'));

$api = new Api('key', $this->client);
$api->setRegion('euw');
$game = $api->currentGame()->currentGame(30447079);

$this->assertTrue($game->participant(30447079) instanceof \LeagueWrap\Dto\CurrentGameParticipant);
}

public function testCurrentGameParticipantMasteries()
{
$this->client->shouldReceive('baseUrl')
->once();
$this->client->shouldReceive('request')
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [
'api_key' => 'key',
])->once()
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json'));

$api = new Api('key', $this->client);
$api->setRegion('euw');
$game = $api->currentGame()->currentGame(30447079);

$participant = $game->participant(28882300);
$this->assertTrue($participant->mastery(4132) instanceof \LeagueWrap\Dto\Mastery);
$this->assertTrue($participant->mastery(4132)->rank == 1);
}

public function testCurrentGameParticipantRunes()
{
$this->client->shouldReceive('baseUrl')
->once();
$this->client->shouldReceive('request')
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [
'api_key' => 'key',
])->once()
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json'));

$api = new Api('key', $this->client);
$api->setRegion('euw');
$game = $api->currentGame()->currentGame(30447079);

$participant = $game->participant(28882300);
$this->assertTrue($participant->rune(5253) instanceof \LeagueWrap\Dto\Rune);
$this->assertTrue($participant->rune(5253)->count == 9);
}


}

0 comments on commit 9b15b4c

Please sign in to comment.