diff --git a/README.md b/README.md index 0219ff2..8489c9b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Challonge/Challonge.php b/src/Challonge/Challonge.php index 854c4fb..c9888d1 100644 --- a/src/Challonge/Challonge.php +++ b/src/Challonge/Challonge.php @@ -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. diff --git a/src/Challonge/DTO/MatchDto.php b/src/Challonge/DTO/MatchDto.php index 28a227f..4a32c59 100644 --- a/src/Challonge/DTO/MatchDto.php +++ b/src/Challonge/DTO/MatchDto.php @@ -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; diff --git a/src/Challonge/DTO/Participant.php b/src/Challonge/DTO/Participant.php index cce6827..3fa9150 100644 --- a/src/Challonge/DTO/Participant.php +++ b/src/Challonge/DTO/Participant.php @@ -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; diff --git a/src/Challonge/DTO/Tournament.php b/src/Challonge/DTO/Tournament.php index d63d57f..3a521eb 100644 --- a/src/Challonge/DTO/Tournament.php +++ b/src/Challonge/DTO/Tournament.php @@ -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; diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index b0c5b2b..e477123 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -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(); } diff --git a/tests/TournamentTest.php b/tests/TournamentTest.php index 111ef31..2189d91 100644 --- a/tests/TournamentTest.php +++ b/tests/TournamentTest.php @@ -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'))); diff --git a/tests/stubs/tournament_missing.json b/tests/stubs/tournament_missing.json new file mode 100644 index 0000000..6e20c2d --- /dev/null +++ b/tests/stubs/tournament_missing.json @@ -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 + } +}