Skip to content

Commit dfe020b

Browse files
authored
Merge pull request #9 from aternosorg/search-projects-test
Add unit tests for SearchProject
2 parents 3d0e688 + 810a032 commit dfe020b

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"hits": [
3+
{
4+
"project_id": "P7dR8mSH",
5+
"project_type": "mod",
6+
"slug": "fabric-api",
7+
"author": "modmuss50",
8+
"title": "Fabric API",
9+
"description": "Lightweight and modular API providing common hooks and intercompatibility measures utilized by mods using the Fabric toolchain.",
10+
"categories": [
11+
"library",
12+
"fabric"
13+
],
14+
"display_categories": [
15+
"library",
16+
"fabric"
17+
],
18+
"versions": [
19+
"1.14",
20+
"1.14.1"
21+
],
22+
"downloads": 3495309,
23+
"follows": 4394,
24+
"icon_url": "https://cdn.modrinth.com/data/P7dR8mSH/icon.png",
25+
"date_created": "2021-01-22T11:04:41.419169Z",
26+
"date_modified": "2023-07-03T13:58:41.940812Z",
27+
"latest_version": "1.14.1",
28+
"license": "Apache-2.0",
29+
"client_side": "optional",
30+
"server_side": "optional",
31+
"gallery": [],
32+
"featured_gallery": null,
33+
"color": 12367004
34+
},
35+
{
36+
"project_id": "AANobbMI",
37+
"project_type": "mod",
38+
"slug": "sodium",
39+
"author": "jellysquid3",
40+
"title": "Sodium",
41+
"description": "A modern rendering engine for Minecraft which greatly improves frame rates and micro-stutter, while fixing graphical issues",
42+
"categories": [
43+
"optimization",
44+
"fabric",
45+
"quilt"
46+
],
47+
"display_categories": [
48+
"optimization",
49+
"fabric",
50+
"quilt"
51+
],
52+
"versions": [
53+
"1.16.3",
54+
"1.16.4",
55+
"1.16.5",
56+
"1.17.1",
57+
"1.18",
58+
"1.18.1",
59+
"1.18.2",
60+
"1.19",
61+
"1.19.1",
62+
"1.19.2",
63+
"1.19.3",
64+
"1.19.4",
65+
"1.20",
66+
"1.20.1"
67+
],
68+
"downloads": 2661759,
69+
"follows": 6503,
70+
"icon_url": "https://cdn.modrinth.com/data/AANobbMI/icon.png",
71+
"date_created": "2021-01-03T00:53:34.185936Z",
72+
"date_modified": "2023-06-07T00:18:42.924130Z",
73+
"latest_version": "1.20.1",
74+
"license": "LGPL-3.0-only",
75+
"client_side": "required",
76+
"server_side": "unsupported",
77+
"gallery": [
78+
"https://cdn.modrinth.com/data/AANobbMI/images/56c4599efcb529a19aed0e118caad4178d7fd540.webp",
79+
"https://cdn.modrinth.com/data/AANobbMI/images/6b0e58705156ba67a6d97a74b9f9ac05da69f502.webp",
80+
"https://cdn.modrinth.com/data/AANobbMI/images/b681a9e87daa53a0e85336a894db70427007149b.webp",
81+
"https://cdn.modrinth.com/data/AANobbMI/images/c39debea7fc623306e9c45148084585399fc59ee.webp",
82+
"https://cdn.modrinth.com/data/AANobbMI/images/d84313e6f57dc9e7896961dbd2dfc2689d482758.webp"
83+
],
84+
"featured_gallery": null,
85+
"color": 8703084
86+
},
87+
{
88+
"project_id": "YL57xq9U",
89+
"project_type": "mod",
90+
"slug": "iris",
91+
"author": "coderbot",
92+
"title": "Iris Shaders",
93+
"description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs",
94+
"categories": [
95+
"decoration",
96+
"optimization",
97+
"fabric",
98+
"quilt"
99+
],
100+
"display_categories": [
101+
"decoration",
102+
"optimization",
103+
"fabric",
104+
"quilt"
105+
],
106+
"versions": [
107+
"1.16.5",
108+
"1.17",
109+
"1.17.1",
110+
"1.18",
111+
"1.18.1",
112+
"1.18.2",
113+
"1.19",
114+
"1.19.1",
115+
"1.19.2",
116+
"1.19.3",
117+
"1.19.4",
118+
"1.20",
119+
"1.20.1"
120+
],
121+
"downloads": 1752965,
122+
"follows": 4535,
123+
"icon_url": "https://cdn.modrinth.com/data/YL57xq9U/dc558eece920db435f9823ce86de0c4cde89800b.png",
124+
"date_created": "2021-05-27T05:11:15.690120Z",
125+
"date_modified": "2023-06-07T00:35:19.290236Z",
126+
"latest_version": "1.20.1",
127+
"license": "LGPL-3.0-only",
128+
"client_side": "required",
129+
"server_side": "unsupported",
130+
"gallery": [
131+
"https://cdn.modrinth.com/data/YL57xq9U/images/1c3d0dfbedf31dbee4e30e20c5329e5db9a881ae.png",
132+
"https://cdn.modrinth.com/data/YL57xq9U/images/2fbd04f5d123577696e29b28bb7981a2bc95a0c8.png"
133+
],
134+
"featured_gallery": "https://cdn.modrinth.com/data/YL57xq9U/images/d382106b9a2b943d06107c31c139c77849f1a0e8.png",
135+
"color": 263172
136+
}
137+
],
138+
"offset": 0,
139+
"limit": 3,
140+
"total_hits": 13560
141+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 Aternos\ModrinthApi\Client\SearchProject;
8+
use Aternos\ModrinthApi\Model\ProjectResult;
9+
use GuzzleHttp\Client;
10+
use GuzzleHttp\Handler\MockHandler;
11+
use GuzzleHttp\HandlerStack;
12+
use GuzzleHttp\Psr7\Response;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class SearchProjectTest extends TestCase
16+
{
17+
18+
public function testGetDataReturnsCorrectProjectModel(): void
19+
{
20+
$projectResultModel = $this->getExampleProjectResultModel();
21+
$searchProject = new SearchProject(new ModrinthAPIClient(), $projectResultModel);
22+
$this->assertEquals($projectResultModel, $searchProject->getData());
23+
}
24+
25+
public function testGetFullProjectReturnsInstanceOfProject(): void
26+
{
27+
$projectResultModel = $this->getExampleProjectResultModel();
28+
// Here we must mock the client, because it requests the user from the API to get all details
29+
$handler = new MockHandler([
30+
new Response(200, [], file_get_contents(__DIR__ . "/../Fixtures/get_project_response.json"))
31+
]);
32+
$client = new ModrinthAPIClient(null, null, new Client(['handler' => HandlerStack::create($handler)]));
33+
34+
$searchProject = new SearchProject($client, $projectResultModel);
35+
$this->assertInstanceOf(Project::class, $searchProject->getFullProject());
36+
}
37+
38+
protected function getExampleProjectResultModel(): ProjectResult
39+
{
40+
$json = json_decode(file_get_contents(__DIR__ . "/../Fixtures/search_projects_response.json"), true);
41+
$modelJson = $json["hits"][0];
42+
return new ProjectResult($modelJson);
43+
}
44+
}

0 commit comments

Comments
 (0)