Skip to content

Commit

Permalink
test: add clash endpoint tests, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dolejska-daniel committed Jun 11, 2023
1 parent a377fec commit e7a6217
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/LeagueAPI/LeagueAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public function getPlayerData(string $puuid): ?Objects\PlayerInfoDto
*
* @link https://developer.riotgames.com/apis#clash-v1/GET_getPlayersByPUUID
*/
public function getPlayersByPUUID(string $encrypted_puuid): ?array
public function getTournamentPlayersByPUUID(string $encrypted_puuid): ?array
{
$resultPromise = $this->setEndpoint("/lol/clash/" . self::RESOURCE_CLASH_VERSION . "/players/by-puuid/$encrypted_puuid")
->setResource(self::RESOURCE_CLASH, "/players/by-puuid/%s")
Expand Down Expand Up @@ -602,7 +602,7 @@ public function getPlayersByPUUID(string $encrypted_puuid): ?array
*
* @link https://developer.riotgames.com/apis#clash-v1/GET_getPlayersBySummoner
*/
public function getPlayersBySummoner(string $summoner_id): ?array
public function getTournamentPlayersBySummoner(string $summoner_id): ?array
{
$resultPromise = $this->setEndpoint("/lol/clash/" . self::RESOURCE_CLASH_VERSION . "/players/by-summoner/$summoner_id")
->setResource(self::RESOURCE_CLASH, "/players/by-summoner/%s")
Expand All @@ -624,7 +624,7 @@ public function getPlayersBySummoner(string $summoner_id): ?array
*
* @param string $team_id
*
* @return Objects\TeamDto|null
* @return Objects\ClashTeamDto|null
*
* @throws SettingsException
* @throws RequestException
Expand All @@ -634,14 +634,14 @@ public function getPlayersBySummoner(string $summoner_id): ?array
*
* @link https://developer.riotgames.com/apis#clash-v1/GET_getTeamById
*/
public function getTeamById(string $team_id): ?Objects\TeamDto
public function getTournamentTeamById(string $team_id): ?Objects\ClashTeamDto
{
$resultPromise = $this->setEndpoint("/lol/clash/" . self::RESOURCE_CLASH_VERSION . "/teams/$team_id")
->setResource(self::RESOURCE_CLASH, "/teams/%s")
->makeCall();

return $this->resolveOrEnqueuePromise($resultPromise, function(array $result) {
return new Objects\TeamDto($result, $this);
return new Objects\ClashTeamDto($result, $this);
});
}

Expand Down Expand Up @@ -722,7 +722,7 @@ public function getTournamentByTeam(string $team_id): ?array
*
* @link https://developer.riotgames.com/apis#clash-v1/GET_getTournamentById
*/
public function getTournamentById(int $tournament_id): ?array
public function getTournamentById(int $tournament_id): ?Objects\TournamentDto
{
$resultPromise = $this->setEndpoint("/lol/clash/" . self::RESOURCE_CLASH_VERSION . "/tournaments/$tournament_id")
->setResource(self::RESOURCE_CLASH, "/tournaments/%d")
Expand Down
18 changes: 9 additions & 9 deletions src/LeagueAPI/Objects/ClashTeamDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Used in:
* clash (v1)
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
* @link https://developer.riotgames.com/apis#clash-v1/GET_getTeamById
*
* @package RiotAPI\LeagueAPI\Objects
Expand All @@ -16,39 +16,39 @@ class ClashTeamDto extends ApiObject
{
/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var string $id
*/
public string $id;

/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var int $tournamentId
*/
public int $tournamentId;

/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var string $name
*/
public string $name;

/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var int $iconId
*/
public int $iconId;

/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var int $tier
*/
Expand All @@ -58,15 +58,15 @@ class ClashTeamDto extends ApiObject
* Summoner ID of the team captain.
*
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var string $captain
*/
public string $captain;

/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var string $abbreviation
*/
Expand All @@ -76,7 +76,7 @@ class ClashTeamDto extends ApiObject
* Team members.
*
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
*
* @var PlayerDto[] $players
*/
Expand Down
28 changes: 14 additions & 14 deletions src/LeagueAPI/Objects/PlayerDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
*
* Used in:
* clash (v1)
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getTournamentTeamById
* @link https://developer.riotgames.com/apis#clash-v1/GET_getTeamById
* - @see LeagueAPI::getPlayersBySummoner
* - @see LeagueAPI::getTournamentPlayersBySummoner
* @link https://developer.riotgames.com/apis#clash-v1/GET_getPlayersBySummoner
* - @see LeagueAPI::getPlayersByPUUID
* - @see LeagueAPI::getTournamentPlayersByPUUID
* @link https://developer.riotgames.com/apis#clash-v1/GET_getPlayersByPUUID
*
* @package RiotAPI\LeagueAPI\Objects
Expand All @@ -38,18 +38,18 @@ class PlayerDto extends ApiObject
{
/**
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getPlayersBySummoner
* - @see LeagueAPI::getPlayersByPUUID
* - @see LeagueAPI::getTournamentTeamById
* - @see LeagueAPI::getTournamentPlayersBySummoner
* - @see LeagueAPI::getTournamentPlayersByPUUID
*
* @var string $summonerId
*/
public string $summonerId;

/**
* Available when received from:
* - @see LeagueAPI::getPlayersBySummoner
* - @see LeagueAPI::getPlayersByPUUID
* - @see LeagueAPI::getTournamentPlayersBySummoner
* - @see LeagueAPI::getTournamentPlayersByPUUID
*
* @var string $teamId
*/
Expand All @@ -59,9 +59,9 @@ class PlayerDto extends ApiObject
* (Legal values: UNSELECTED, FILL, TOP, JUNGLE, MIDDLE, BOTTOM, UTILITY).
*
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getPlayersBySummoner
* - @see LeagueAPI::getPlayersByPUUID
* - @see LeagueAPI::getTournamentTeamById
* - @see LeagueAPI::getTournamentPlayersBySummoner
* - @see LeagueAPI::getTournamentPlayersByPUUID
*
* @var string $position
*/
Expand All @@ -71,9 +71,9 @@ class PlayerDto extends ApiObject
* (Legal values: CAPTAIN, MEMBER).
*
* Available when received from:
* - @see LeagueAPI::getTeamById
* - @see LeagueAPI::getPlayersBySummoner
* - @see LeagueAPI::getPlayersByPUUID
* - @see LeagueAPI::getTournamentTeamById
* - @see LeagueAPI::getTournamentPlayersBySummoner
* - @see LeagueAPI::getTournamentPlayersByPUUID
*
* @var string $role
*/
Expand Down
1 change: 1 addition & 0 deletions tests/DummyData/GET_lol-clash-v1-tournaments-27641.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:3:{s:7:"headers";a:14:{s:4:"Date";s:29:"Sun, 11 Jun 2023 08:00:51 GMT";s:12:"Content-Type";s:30:"application/json;charset=utf-8";s:17:"Transfer-Encoding";s:7:"chunked";s:10:"Connection";s:10:"keep-alive";s:4:"Vary";s:15:"Accept-Encoding";s:16:"X-App-Rate-Limit";s:12:"20:1,100:120";s:22:"X-App-Rate-Limit-Count";s:9:"1:1,1:120";s:19:"X-Method-Rate-Limit";s:5:"10:60";s:25:"X-Method-Rate-Limit-Count";s:4:"1:60";s:20:"X-Riot-Edge-Trace-Id";s:36:"9ef5bd00-f133-420b-b712-eeb5c94ddd1b";s:27:"Access-Control-Allow-Origin";s:1:"*";s:28:"Access-Control-Allow-Methods";s:31:"GET, PUT, DELETE, POST, OPTIONS";s:28:"Access-Control-Allow-Headers";s:82:"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range";s:29:"Access-Control-Expose-Headers";s:28:"Content-Length,Content-Range";}s:8:"response";s:178:"{"id":27641,"themeId":1,"nameKey":"bandle_city","nameKeySecondary":"day_1","schedule":[{"id":27561,"registrationTime":1685803500000,"startTime":1685818800000,"cancelled":false}]}";s:4:"code";i:200;}
1 change: 1 addition & 0 deletions tests/DummyData/GET_lol-clash-v1-tournaments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:3:{s:7:"headers";a:14:{s:4:"Date";s:29:"Sun, 11 Jun 2023 07:58:41 GMT";s:12:"Content-Type";s:30:"application/json;charset=utf-8";s:17:"Transfer-Encoding";s:7:"chunked";s:10:"Connection";s:10:"keep-alive";s:4:"Vary";s:15:"Accept-Encoding";s:16:"X-App-Rate-Limit";s:12:"20:1,100:120";s:22:"X-App-Rate-Limit-Count";s:9:"1:1,1:120";s:19:"X-Method-Rate-Limit";s:5:"10:60";s:25:"X-Method-Rate-Limit-Count";s:4:"1:60";s:20:"X-Riot-Edge-Trace-Id";s:36:"644b3a6b-2e3b-4eaa-bb60-b3d685c15171";s:27:"Access-Control-Allow-Origin";s:1:"*";s:28:"Access-Control-Allow-Methods";s:31:"GET, PUT, DELETE, POST, OPTIONS";s:28:"Access-Control-Allow-Headers";s:82:"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range";s:29:"Access-Control-Expose-Headers";s:28:"Content-Length,Content-Range";}s:8:"response";s:359:"[{"id":27721,"themeId":1,"nameKey":"bandle_city","nameKeySecondary":"day_4","schedule":[{"id":27641,"registrationTime":1687099500000,"startTime":1687114800000,"cancelled":false}]},{"id":27701,"themeId":1,"nameKey":"bandle_city","nameKeySecondary":"day_3","schedule":[{"id":27621,"registrationTime":1687013100000,"startTime":1687028400000,"cancelled":false}]}]";s:4:"code";i:200;}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

/**
* Copyright (C) 2016-2023 Daniel Dolejška
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace LeagueAPI\EndpointObjectIntegrity;

use RiotAPI\Base\Definitions\Region;
use RiotAPI\LeagueAPI\LeagueAPI;
use RiotAPI\LeagueAPI\Objects;
use RiotAPI\Tests\RiotAPITestCase;


class ClashEndpointObjectIntegrityTest extends RiotAPITestCase
{
public function testInit()
{
$api = new LeagueAPI([
LeagueAPI::SET_KEY => RiotAPITestCase::getApiKey(),
LeagueAPI::SET_REGION => Region::EUROPE_EAST,
LeagueAPI::SET_USE_DUMMY_DATA => true,
LeagueAPI::SET_SAVE_DUMMY_DATA => getenv('SAVE_DUMMY_DATA') ?? false,
]);

$this->assertInstanceOf(LeagueAPI::class, $api);

return $api;
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournaments(LeagueAPI $api)
{
// Get library processed results
/** @var Objects\ChallengeConfigInfoDto[] $result */
$result = $api->getTournaments();
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, Objects\TournamentDto::class);
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournamentByTeam(LeagueAPI $api)
{
$this->markTestSkipped("No DummyData available for this endpoint yet.");

// Get library processed results
/** @var Objects\ClashTeamDto $result */
$result = $api->getTournamentByTeam("");
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidity($result, $rawResult, Objects\ClashTeamDto::class);
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournamentById(LeagueAPI $api)
{
// Get library processed results
/** @var Objects\TournamentDto $result */
$result = $api->getTournamentById(27641);
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidity($result, $rawResult, Objects\TournamentDto::class);
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournamentPlayersByPUUID(LeagueAPI $api)
{
$this->markTestSkipped("No DummyData available for this endpoint yet.");

// Get library processed results
/** @var Objects\PlayerDto[] $result */
$result = $api->getTournamentPlayersByPUUID("");
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, Objects\PlayerDto::class);
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournamentPlayersBySummoner(LeagueAPI $api)
{
$this->markTestSkipped("No DummyData available for this endpoint yet.");

// Get library processed results
/** @var Objects\PlayerDto[] $result */
$result = $api->getTournamentPlayersBySummoner("LfgVCG8zj31owTI_L8s0TkHZCV4yDVJG_f_993LYz4sKdPzLqSERQn08FA");
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, Objects\PlayerDto::class);
}

/**
* @depends testInit
*
* @param LeagueAPI $api
*/
public function testGetTournamentTeamById(LeagueAPI $api)
{
$this->markTestSkipped("No DummyData available for this endpoint yet.");

// Get library processed results
/** @var Objects\PlayerDto[] $result */
$result = $api->getTournamentTeamById("");
// Get raw result
$rawResult = $api->getResult();

$this->checkObjectPropertiesAndDataValidityOfObjectList($result, $rawResult, Objects\PlayerDto::class);
}

}

0 comments on commit e7a6217

Please sign in to comment.