Skip to content

Commit

Permalink
mark DTOs as ignoring missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekz committed Jul 13, 2021
1 parent 74dfcc3 commit 470f7f0
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Now you're ready to make requests:
$tournament = $challonge->fetchTournament('challongephptest');
```

## API Updates
Challonge does not lock their API and has been consistently adding new fields to objects, thus breaking strongly typed DTOs.

As of 3.0.4, all three DTOs have been marked to ignore missing fields. If Challonge adds a new field, it will no longer throw a `DataTransferObjectError`, but the DTO will also however not contain that new field.


## Documentation
As the package is fully type-hinted, everything should be self documenting, however there is documentation in the wiki.

## Contact
Expand Down
2 changes: 1 addition & 1 deletion src/Challonge/Challonge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Challonge
* ChallongePHP version.
* Required to pass into Challonge.
*/
protected string $version = '3.0.0';
protected string $version = '3.0.4';

/**
* PSR-18 compatible HTTP client wrapped in our wrapper.
Expand Down
6 changes: 6 additions & 0 deletions src/Challonge/DTO/MatchDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class MatchDto extends DataTransferObject
{
use DtoClientTrait;

/**
* Due to Challonge not locking their API and constantly adding new fields...
* @var bool
*/
protected bool $ignoreMissing = true;

public ?int $attachment_count;
public ?string $completed_at;
public string $created_at;
Expand Down
6 changes: 6 additions & 0 deletions src/Challonge/DTO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class Participant extends DataTransferObject
{
use DtoClientTrait;

/**
* Due to Challonge not locking their API and constantly adding new fields...
* @var bool
*/
protected bool $ignoreMissing = true;

public bool $active;
public bool $check_in_open;
public ?string $checked_in_at;
Expand Down
6 changes: 6 additions & 0 deletions src/Challonge/DTO/Tournament.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class Tournament extends DataTransferObject
{
use DtoClientTrait;

/**
* Due to Challonge not locking their API and constantly adding new fields...
* @var bool
*/
protected bool $ignoreMissing = true;

public int $id;
public string $name;
public string $url;
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void
// real
//$http = new Client();

$this->challonge = new Challonge($http, '');
$this->challonge = new Challonge($http, '', true);

parent::setUp();
}
Expand Down
9 changes: 9 additions & 0 deletions tests/TournamentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

class TournamentTest extends BaseTestCase
{
public function test_tournament_ignore_missing(): void
{
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/stubs/tournament_missing.json')));

$response = $this->challonge->fetchTournament('9044420');

$this->assertEquals('challongephp test', $response->name);
}

public function test_tournament_index(): void
{
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/stubs/tournament_index.json')));
Expand Down
100 changes: 100 additions & 0 deletions tests/stubs/tournament_missing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"tournament":{
"id":9044420,
"name":"challongephp test",
"url":"challongephptest",
"description":"",
"tournament_type":"single elimination",
"started_at":"2020-10-25T00:45:24.771+13:00",
"completed_at":null,
"require_score_agreement":false,
"notify_users_when_matches_open":true,
"created_at":"2020-10-25T00:44:42.701+13:00",
"updated_at":"2020-10-25T00:45:24.863+13:00",
"state":"underway",
"open_signup":false,
"notify_users_when_the_tournament_ends":true,
"progress_meter":0,
"quick_advance":false,
"hold_third_place_match":false,
"pts_for_game_win":"0.0",
"pts_for_game_tie":"0.0",
"pts_for_match_win":"1.0",
"pts_for_match_tie":"0.5",
"pts_for_bye":"1.0",
"swiss_rounds":0,
"private":false,
"ranked_by":"match wins",
"show_rounds":true,
"hide_forum":false,
"sequential_pairings":false,
"accept_attachments":false,
"rr_pts_for_game_win":"0.0",
"rr_pts_for_game_tie":"0.0",
"rr_pts_for_match_win":"1.0",
"rr_pts_for_match_tie":"0.5",
"created_by_api":false,
"credit_capped":false,
"category":null,
"hide_seeds":false,
"prediction_method":0,
"predictions_opened_at":null,
"anonymous_voting":false,
"max_predictions_per_user":1,
"signup_cap":null,
"game_id":1352,
"participants_count":3,
"group_stages_enabled":false,
"allow_participant_match_reporting":true,
"teams":false,
"check_in_duration":null,
"start_at":"2020-10-25T00:30:00.000+13:00",
"started_checking_in_at":null,
"tie_breaks":[
"match wins vs tied",
"game wins",
"points scored"
],
"locked_at":null,
"event_id":null,
"public_predictions_before_start_time":false,
"ranked":false,
"grand_finals_modifier":null,
"predict_the_losers_bracket":false,
"spam":null,
"ham":null,
"rr_iterations":1,
"tournament_registration_id":null,
"donation_contest_enabled":null,
"mandatory_donation":null,
"non_elimination_tournament_data":{
"participants_per_match":""
},
"auto_assign_stations":null,
"only_start_matches_with_stations":null,
"registration_fee":"0.0",
"registration_type":"free",
"split_participants":false,
"allowed_regions":null,
"show_participant_country":null,
"program_id":null,
"program_classification_ids_allowed":null,
"description_source":"",
"subdomain":null,
"full_challonge_url":"https://challonge.com/challongephptest",
"live_image_url":"https://challonge.com/challongephptest.svg",
"sign_up_url":null,
"review_before_finalizing":true,
"accepting_predictions":false,
"participants_locked":true,
"game_name":"Crash Team Racing",
"participants_swappable":false,
"team_convertable":false,
"group_stages_were_started":false,
"team_size_range":null,
"toxic":null,
"use_new_style":null,
"optional_display_data":[],
"testMissing":1
}
}

0 comments on commit 470f7f0

Please sign in to comment.