Skip to content

Commit 3d0e688

Browse files
authored
Merge pull request #8 from aternosorg/add-unit-tests
Add unit tests for Notification and Project
2 parents f97c145 + c72c67a commit 3d0e688

File tree

6 files changed

+350
-0
lines changed

6 files changed

+350
-0
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
-->
1212
<directory>tests/Integration/Client</directory>
1313
</testsuite>
14+
<testsuite name="unit">
15+
<directory>tests/Unit/Client</directory>
16+
</testsuite>
1417
</testsuites>
1518
<source>
1619
<include>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"id": "UUVVWWXX",
3+
"user_id": "Dc7EYhxG",
4+
"type": "project_update",
5+
"title": "**My Project** has been updated!",
6+
"text": "The project, My Project, has released a new version: 1.0.0",
7+
"link": "mod/AABBCCDD/version/IIJJKKLL",
8+
"read": false,
9+
"created": "string",
10+
"actions": [
11+
{
12+
"title": "Accept",
13+
"action_route": [
14+
"POST",
15+
"team/{id}/join"
16+
]
17+
}
18+
]
19+
}
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
{
2+
"id": "mOgUt4GM",
3+
"slug": "modmenu",
4+
"project_type": "mod",
5+
"team": "VMz4FpgB",
6+
"title": "Mod Menu",
7+
"description": "Adds a mod menu to view the list of mods you have installed.",
8+
"body": "![Mod Menu Banner](https://i.imgur.com/dMYWAjn.png)\nHard to be more descriptive than that. It enriches the standard Minecraft menu with an interface displaying a one-dimensional array of modifications\n\n\n\nMod Menu requires [Fabric Loader](https://fabricmc.net/use/) and [Fabric API](https://www.modrinth.com/mod/fabric-api)\n\nCheck out the [Terraformers Discord Server](https://discord.gg/jEGF5fb) to chat about Mod Menu and other Fabric mods!\n\nA picture's worth 2 words\n\n![Mod Menu Screenshot](https://i.imgur.com/wp83YOP.png)\n\n\n### Mod Menu is a mod for Fabric, and there are no plans to port this mod to Forge.",
9+
"body_url": null,
10+
"published": "2020-11-06T05:11:04.725058Z",
11+
"updated": "2023-07-18T20:52:37.015257Z",
12+
"approved": "2020-11-06T05:11:04.725058Z",
13+
"queued": null,
14+
"status": "approved",
15+
"requested_status": null,
16+
"moderator_message": null,
17+
"license": {
18+
"id": "MIT",
19+
"name": "MIT License",
20+
"url": null
21+
},
22+
"client_side": "required",
23+
"server_side": "unsupported",
24+
"downloads": 1697771,
25+
"followers": 5359,
26+
"categories": [
27+
"utility"
28+
],
29+
"additional_categories": [],
30+
"game_versions": [
31+
"1.14.4",
32+
"1.15.2",
33+
"1.16.1",
34+
"1.16.4",
35+
"1.16.5",
36+
"1.17",
37+
"1.17.1",
38+
"1.17-pre1",
39+
"1.18",
40+
"1.18.1",
41+
"1.18.1-pre1",
42+
"1.18.1-rc1",
43+
"1.18.1-rc2",
44+
"1.18.1-rc3",
45+
"1.18.2",
46+
"1.18.2-pre1",
47+
"1.18.2-pre2",
48+
"1.18.2-pre3",
49+
"1.18.2-rc1",
50+
"1.19",
51+
"1.19.1",
52+
"1.19.1-pre2",
53+
"1.19.1-rc1",
54+
"1.19.2",
55+
"1.19.3",
56+
"1.19.4",
57+
"1.19.4-pre1",
58+
"1.19.4-pre2",
59+
"1.19.4-pre3",
60+
"1.19.4-pre4",
61+
"1.19.4-rc1",
62+
"1.19.4-rc2",
63+
"1.19.4-rc3",
64+
"1.19-pre1",
65+
"1.19-pre2",
66+
"1.19-pre3",
67+
"1.19-pre4",
68+
"1.20",
69+
"1.20.1",
70+
"1.20.1-rc1",
71+
"1.20-pre1",
72+
"1.20-pre2",
73+
"1.20-pre3",
74+
"1.20-pre4",
75+
"1.20-pre5",
76+
"1.20-pre6",
77+
"1.20-pre7",
78+
"1.20-rc1",
79+
"21w06a",
80+
"21w14a",
81+
"21w37a",
82+
"21w38a",
83+
"22w03a",
84+
"22w05a",
85+
"22w06a",
86+
"22w07a",
87+
"22w15a",
88+
"22w16b",
89+
"22w17a",
90+
"22w18a",
91+
"22w19a",
92+
"22w24a",
93+
"22w43a",
94+
"23w03a",
95+
"23w05a",
96+
"23w07a",
97+
"23w12a",
98+
"23w13a",
99+
"23w13a_or_b",
100+
"23w14a",
101+
"23w16a",
102+
"23w17a",
103+
"23w18a"
104+
],
105+
"loaders": [
106+
"fabric",
107+
"quilt"
108+
],
109+
"versions": [
110+
"M3KFXLhq",
111+
"DgzrfgAZ",
112+
"O90fUm3q",
113+
"zC13OZD9",
114+
"7QWIhei3",
115+
"79rtoAM6",
116+
"kBofQyu4",
117+
"TleLdS1A",
118+
"PqgXyy3N",
119+
"Mnl0OeFI",
120+
"pxj9L3Vy",
121+
"6YvLIUDN",
122+
"wb5nbuL5",
123+
"bPE0GIoY",
124+
"pqlMITZQ",
125+
"RIf7gcLA",
126+
"Gz5wa6j2",
127+
"EDbIonje",
128+
"wRE7Emzz",
129+
"mzVbb1XI",
130+
"bHODZExo",
131+
"a8bewBQT",
132+
"NyFB1gry",
133+
"oQr5VO7q",
134+
"u955lyFM",
135+
"E4QBMVtO",
136+
"c6uDXZX8",
137+
"bojzkt4w",
138+
"4Ar2wg0k",
139+
"G8sCBZ1X",
140+
"JyL5b75a",
141+
"GOPQZTVp",
142+
"Wr4GfZdy",
143+
"tlM0eBmY",
144+
"DOitjZ89",
145+
"XtL1i60M",
146+
"VaZTuVan",
147+
"FMqdptUn",
148+
"aH8qgnVM",
149+
"9xECQHnM",
150+
"LVxVja5i",
151+
"JOqf8AZn",
152+
"WKj0jgYj",
153+
"jZQ0G78K",
154+
"PN4NcBa1",
155+
"WkUCkcQA",
156+
"3CD6YUw1",
157+
"JPP6w2U1",
158+
"eueI9czw",
159+
"4JrWqhWw",
160+
"Ui2loaCY",
161+
"fw5MM4c4",
162+
"6f25OJ7w",
163+
"E4VKK6kQ",
164+
"y8cYdaYa",
165+
"GYRoFp1I",
166+
"Tk7mCRX1",
167+
"aShj7736",
168+
"dP3zrFbp",
169+
"cx9D94fU",
170+
"pnFEFiHq",
171+
"ybXxCvz4",
172+
"NsD1IoUs",
173+
"oU5qfeR6",
174+
"2Ys0a7JE",
175+
"8TOgNwQL",
176+
"kQDE01D3",
177+
"3umfHb6R",
178+
"Gbkn1raO",
179+
"d86kV6wd",
180+
"NAs8eiQa",
181+
"RxrqnH1z",
182+
"GI1HTA1O",
183+
"sI3kiPZE",
184+
"4dReZoTJ",
185+
"7mdkE3Od",
186+
"qDXCbEz4",
187+
"IPLgxPn7",
188+
"V4hnfgRO",
189+
"nVxObSbX",
190+
"7kh2ofyR",
191+
"eIrlBn1Z",
192+
"yA8g3pEj",
193+
"oqeCO757",
194+
"4LXaG2xg",
195+
"5qqTBb38",
196+
"7E8dbVv0",
197+
"5aw4r6fS",
198+
"pyDmgV07",
199+
"jRqFAHRH",
200+
"4EOA40rU",
201+
"gSoPJyVn",
202+
"RtaGQNyd",
203+
"sXVmzBDB",
204+
"U31K6311",
205+
"JYTmttex",
206+
"pged5sGx",
207+
"5e62j63G",
208+
"nM5QaZNo",
209+
"aMxXwo9x",
210+
"3gwnUSKz",
211+
"yjjsLqbS",
212+
"RdCGzY7B",
213+
"EuNUYds8",
214+
"iZRiOnnj",
215+
"M7LIgtWJ",
216+
"RTFDnTKf",
217+
"CtMNOUcV",
218+
"zv46i3PW",
219+
"VHzvWfY2",
220+
"sLzitH81",
221+
"id0aLmxO",
222+
"eTCL1uh8",
223+
"lMqXEzUw"
224+
],
225+
"icon_url": "https://cdn.modrinth.com/data/mOgUt4GM/icon.png",
226+
"issues_url": "https://github.com/TerraformersMC/ModMenu/issues",
227+
"source_url": "https://github.com/TerraformersMC/ModMenu",
228+
"wiki_url": "https://github.com/TerraformersMC/ModMenu/wiki",
229+
"discord_url": "https://discord.gg/jEGF5fb",
230+
"donation_urls": [],
231+
"gallery": [
232+
{
233+
"url": "https://cdn.modrinth.com/data/mOgUt4GM/images/5726bbaf7d0ea53e55b6e666af5d3e1861758334.png",
234+
"featured": false,
235+
"title": "Mod Menu",
236+
"description": null,
237+
"created": "2022-02-28T02:33:37.984225Z",
238+
"ordering": 0
239+
}
240+
],
241+
"color": 1330428,
242+
"thread_id": "mOgUt4GM",
243+
"monetization_status": "monetized"
244+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "Dc7EYhxG",
3+
"username": "Prospector",
4+
"name": null,
5+
"avatar_url": "https://cdn.modrinth.com/user/Dc7EYhxG/64d0b4c4cdcb33f3b7d4b31b140e83b199b00f3c.png",
6+
"bio": "Lead Frontend Developer/Designer and Archivist at Modrinth. Founder of ModFest, co-founder of TerraformersMC. Creator of Traverse and Mod Menu.",
7+
"created": "2020-11-06T04:56:05.014379Z",
8+
"role": "admin",
9+
"badges": 0,
10+
"payout_data": null,
11+
"auth_providers": null,
12+
"email": null,
13+
"email_verified": null,
14+
"has_password": null,
15+
"has_totp": null,
16+
"github_id": null
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Aternos\ModrinthApi\Tests\Unit\Client\Models;
4+
5+
use Aternos\ModrinthApi\Client\ModrinthAPIClient;
6+
use Aternos\ModrinthApi\Client\Notification;
7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Handler\MockHandler;
9+
use GuzzleHttp\HandlerStack;
10+
use GuzzleHttp\Psr7\Response;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class NotificationTest extends TestCase
14+
{
15+
16+
public function testGetDataReturnsCorrectNotificationModel(): void
17+
{
18+
$notificationModel = $this->getExampleNotificationModel();
19+
$notification = new Notification(new ModrinthAPIClient(), $notificationModel);
20+
$this->assertEquals($notificationModel, $notification->getData());
21+
}
22+
23+
public function testGetUserReturnsCorrectUser(): void
24+
{
25+
// Here we must mock the client, because it requests the user from the API to get all details
26+
$handler = new MockHandler([
27+
new Response(200, [], file_get_contents(__DIR__ . "/../Fixtures/get_user_response.json")),
28+
new Response(200, [], file_get_contents(__DIR__ . "/../Fixtures/get_user_response.json"))
29+
]);
30+
$client = new ModrinthAPIClient(null, null, new Client(['handler' => HandlerStack::create($handler)]));
31+
32+
$notification = new Notification($client, $this->getExampleNotificationModel());
33+
// Dc7EYhxG -> https://modrinth.com/user/Prospector
34+
$user = $client->getUser("Dc7EYhxG");
35+
$this->assertEquals($user, $notification->getUser());
36+
}
37+
38+
protected function getExampleNotificationModel(): \Aternos\ModrinthApi\Model\Notification
39+
{
40+
$json = json_decode(file_get_contents(__DIR__ . "/../Fixtures/get_notification_response.json"), true);
41+
return new \Aternos\ModrinthApi\Model\Notification($json);
42+
}
43+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Aternos\ModrinthApi\Tests\Unit\Client\Models;
4+
5+
use Aternos\ModrinthApi\Client\ModrinthAPIClient;
6+
use Aternos\ModrinthApi\Client\Project;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ProjectTest extends TestCase
10+
{
11+
12+
public function testGetDataReturnsCorrectProjectModel(): void
13+
{
14+
$projectModel = $this->getExampleProjectModel();
15+
$project = new Project(new ModrinthAPIClient(), $projectModel);
16+
$this->assertEquals($projectModel, $project->getData());
17+
}
18+
19+
protected function getExampleProjectModel(): \Aternos\ModrinthApi\Model\Project
20+
{
21+
$json = json_decode(file_get_contents(__DIR__ . "/../Fixtures/get_project_response.json"), true);
22+
return new \Aternos\ModrinthApi\Model\Project($json);
23+
}
24+
}

0 commit comments

Comments
 (0)