Skip to content

Commit 470f7f0

Browse files
committed
mark DTOs as ignoring missing fields
1 parent 74dfcc3 commit 470f7f0

File tree

8 files changed

+136
-2
lines changed

8 files changed

+136
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ Now you're ready to make requests:
5656
$tournament = $challonge->fetchTournament('challongephptest');
5757
```
5858

59+
## API Updates
60+
Challonge does not lock their API and has been consistently adding new fields to objects, thus breaking strongly typed DTOs.
61+
62+
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.
63+
64+
65+
## Documentation
5966
As the package is fully type-hinted, everything should be self documenting, however there is documentation in the wiki.
6067

6168
## Contact

src/Challonge/Challonge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Challonge
1414
* ChallongePHP version.
1515
* Required to pass into Challonge.
1616
*/
17-
protected string $version = '3.0.0';
17+
protected string $version = '3.0.4';
1818

1919
/**
2020
* PSR-18 compatible HTTP client wrapped in our wrapper.

src/Challonge/DTO/MatchDto.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class MatchDto extends DataTransferObject
99
{
1010
use DtoClientTrait;
1111

12+
/**
13+
* Due to Challonge not locking their API and constantly adding new fields...
14+
* @var bool
15+
*/
16+
protected bool $ignoreMissing = true;
17+
1218
public ?int $attachment_count;
1319
public ?string $completed_at;
1420
public string $created_at;

src/Challonge/DTO/Participant.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class Participant extends DataTransferObject
99
{
1010
use DtoClientTrait;
1111

12+
/**
13+
* Due to Challonge not locking their API and constantly adding new fields...
14+
* @var bool
15+
*/
16+
protected bool $ignoreMissing = true;
17+
1218
public bool $active;
1319
public bool $check_in_open;
1420
public ?string $checked_in_at;

src/Challonge/DTO/Tournament.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class Tournament extends DataTransferObject
1212
{
1313
use DtoClientTrait;
1414

15+
/**
16+
* Due to Challonge not locking their API and constantly adding new fields...
17+
* @var bool
18+
*/
19+
protected bool $ignoreMissing = true;
20+
1521
public int $id;
1622
public string $name;
1723
public string $url;

tests/BaseTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function setUp(): void
2323
// real
2424
//$http = new Client();
2525

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

2828
parent::setUp();
2929
}

tests/TournamentTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
class TournamentTest extends BaseTestCase
99
{
10+
public function test_tournament_ignore_missing(): void
11+
{
12+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/stubs/tournament_missing.json')));
13+
14+
$response = $this->challonge->fetchTournament('9044420');
15+
16+
$this->assertEquals('challongephp test', $response->name);
17+
}
18+
1019
public function test_tournament_index(): void
1120
{
1221
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/stubs/tournament_index.json')));
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"tournament":{
3+
"id":9044420,
4+
"name":"challongephp test",
5+
"url":"challongephptest",
6+
"description":"",
7+
"tournament_type":"single elimination",
8+
"started_at":"2020-10-25T00:45:24.771+13:00",
9+
"completed_at":null,
10+
"require_score_agreement":false,
11+
"notify_users_when_matches_open":true,
12+
"created_at":"2020-10-25T00:44:42.701+13:00",
13+
"updated_at":"2020-10-25T00:45:24.863+13:00",
14+
"state":"underway",
15+
"open_signup":false,
16+
"notify_users_when_the_tournament_ends":true,
17+
"progress_meter":0,
18+
"quick_advance":false,
19+
"hold_third_place_match":false,
20+
"pts_for_game_win":"0.0",
21+
"pts_for_game_tie":"0.0",
22+
"pts_for_match_win":"1.0",
23+
"pts_for_match_tie":"0.5",
24+
"pts_for_bye":"1.0",
25+
"swiss_rounds":0,
26+
"private":false,
27+
"ranked_by":"match wins",
28+
"show_rounds":true,
29+
"hide_forum":false,
30+
"sequential_pairings":false,
31+
"accept_attachments":false,
32+
"rr_pts_for_game_win":"0.0",
33+
"rr_pts_for_game_tie":"0.0",
34+
"rr_pts_for_match_win":"1.0",
35+
"rr_pts_for_match_tie":"0.5",
36+
"created_by_api":false,
37+
"credit_capped":false,
38+
"category":null,
39+
"hide_seeds":false,
40+
"prediction_method":0,
41+
"predictions_opened_at":null,
42+
"anonymous_voting":false,
43+
"max_predictions_per_user":1,
44+
"signup_cap":null,
45+
"game_id":1352,
46+
"participants_count":3,
47+
"group_stages_enabled":false,
48+
"allow_participant_match_reporting":true,
49+
"teams":false,
50+
"check_in_duration":null,
51+
"start_at":"2020-10-25T00:30:00.000+13:00",
52+
"started_checking_in_at":null,
53+
"tie_breaks":[
54+
"match wins vs tied",
55+
"game wins",
56+
"points scored"
57+
],
58+
"locked_at":null,
59+
"event_id":null,
60+
"public_predictions_before_start_time":false,
61+
"ranked":false,
62+
"grand_finals_modifier":null,
63+
"predict_the_losers_bracket":false,
64+
"spam":null,
65+
"ham":null,
66+
"rr_iterations":1,
67+
"tournament_registration_id":null,
68+
"donation_contest_enabled":null,
69+
"mandatory_donation":null,
70+
"non_elimination_tournament_data":{
71+
"participants_per_match":""
72+
},
73+
"auto_assign_stations":null,
74+
"only_start_matches_with_stations":null,
75+
"registration_fee":"0.0",
76+
"registration_type":"free",
77+
"split_participants":false,
78+
"allowed_regions":null,
79+
"show_participant_country":null,
80+
"program_id":null,
81+
"program_classification_ids_allowed":null,
82+
"description_source":"",
83+
"subdomain":null,
84+
"full_challonge_url":"https://challonge.com/challongephptest",
85+
"live_image_url":"https://challonge.com/challongephptest.svg",
86+
"sign_up_url":null,
87+
"review_before_finalizing":true,
88+
"accepting_predictions":false,
89+
"participants_locked":true,
90+
"game_name":"Crash Team Racing",
91+
"participants_swappable":false,
92+
"team_convertable":false,
93+
"group_stages_were_started":false,
94+
"team_size_range":null,
95+
"toxic":null,
96+
"use_new_style":null,
97+
"optional_display_data":[],
98+
"testMissing":1
99+
}
100+
}

0 commit comments

Comments
 (0)