From 3ebea9ac1b8a79338766a52e1117238fd9ee9895 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Mon, 19 Oct 2026 18:40:10 +0200 Subject: [PATCH] prefix wrapper methods that send a request with fetch --- README.md | 28 +++++++++++-------- src/Client/Notification.php | 5 ++-- src/Client/Project.php | 5 ++-- src/Client/ProjectTrait.php | 13 +++++---- src/Client/SearchProject.php | 8 ++++-- src/Client/TeamMember.php | 5 ++-- src/Client/Threads/Report.php | 20 +++++++------ src/Client/Threads/Thread.php | 12 +++++--- src/Client/Threads/ThreadMessage.php | 5 ++-- src/Client/User.php | 20 +++++++------ src/Client/Version.php | 10 ++++--- src/Client/VersionDependency.php | 12 +++++--- tests/Integration/Client/ClientTest.php | 22 +++++++-------- tests/Unit/Client/Models/NotificationTest.php | 4 +-- tests/Unit/Client/Models/ProjectTest.php | 12 ++++---- .../Unit/Client/Models/SearchProjectTest.php | 12 ++++---- tests/Unit/Client/Models/TeamMemberTest.php | 8 +++--- tests/Unit/Client/Models/UserTest.php | 16 +++++------ .../Client/Models/VersionDependencyTest.php | 16 +++++------ tests/Unit/Client/Models/VersionTest.php | 8 +++--- tests/Unit/Client/Threads/ReportTest.php | 28 +++++++++---------- .../Unit/Client/Threads/ThreadMessageTest.php | 8 +++--- tests/Unit/Client/Threads/ThreadTest.php | 16 +++++------ 23 files changed, 162 insertions(+), 131 deletions(-) diff --git a/README.md b/README.md index 0bd07be..2ff9476 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ and some wrappers around it to improve the usability. The generated code can be found in `src/Api` and `src/Model`. It is recommended to use the wrappers in `src/Client` instead. +The wrappers like `Project`, `Version` or `User` extend the generated models, so all getters of the models +can be used directly, e.g. `$project->getTitle()`. +Methods of the wrappers that send a request to the API start with `fetch`, e.g. `$project->fetchMembers()`. + ## Requirements - PHP 8.4.1 or newer - PHP extensions: curl, json, mbstring @@ -88,7 +92,7 @@ $allProjects = $projects->getResultsFromFollowingPages(); Search results are `SearchProject` objects. They only contain the data returned by the search, but you can fetch the full project or the author: ```php -$project = $projects[0]->getFullProject(); +$project = $projects[0]->fetchFullProject(); $author = $projects[0]->fetchAuthor(); ``` @@ -188,16 +192,16 @@ $versions = $project->fetchProjectVersions(); $versions = $project->fetchProjectVersions(["paper"], ["1.21"]); // the members of the project team -$members = $project->getMembers(); +$members = $project->fetchMembers(); // the dependencies of the project // projects can depend on other projects or directly on specific versions -$dependencies = $project->getDependencies(); +$dependencies = $project->fetchDependencies(); $dependencyProjects = $dependencies->getProjects(); $dependencyVersions = $dependencies->getVersions(); // the moderation thread of the project (requires authentication, not available for search results) -$thread = $project->getThread(); +$thread = $project->fetchThread(); ``` Note that `$project->getVersions()` is the getter of the generated model and only returns the version ids. @@ -221,13 +225,13 @@ $versions = $modrinthClient->getVersions(["xzRGr4AC", "EwNN8uNA"]); The `Version` wrapper provides methods to fetch related data: ```php -$project = $version->getProject(); -$author = $version->getAuthor(); +$project = $version->fetchProject(); +$author = $version->fetchAuthor(); foreach ($version->getDependencies() as $dependency) { // a dependency can point to a project, a specific version or both - $dependencyProject = $dependency->getProject(); - $dependencyVersion = $dependency->getVersion(); + $dependencyProject = $dependency->fetchProject(); + $dependencyVersion = $dependency->fetchVersion(); } // get the download url of the primary file @@ -275,16 +279,16 @@ $users = $modrinthClient->getUsers(["MpxzqsyW", "Dc7EYhxG"]); $user = $modrinthClient->getCurrentUser(); // get the projects of a user -$projects = $user->getProjects(); +$projects = $user->fetchProjects(); // get the projects a user follows (requires authentication) -$projects = $user->getFollowedProjects(); +$projects = $user->fetchFollowedProjects(); // get the notifications of a user (requires authentication) -$notifications = $user->getNotifications(); +$notifications = $user->fetchNotifications(); // get the payout history of a user (requires authentication) -$history = $user->getPayoutHistory(); +$history = $user->fetchPayoutHistory(); ``` ## Teams diff --git a/src/Client/Notification.php b/src/Client/Notification.php index c90bb64..83a08f2 100644 --- a/src/Client/Notification.php +++ b/src/Client/Notification.php @@ -16,11 +16,12 @@ public function __construct( } /** - * Get the user that received the notification + * Fetch the user that received the notification + * This sends a request to the Modrinth API every time it is called. * @return User * @throws ApiException */ - public function getUser(): User + public function fetchUser(): User { return $this->client->getUser($this->getUserId()); } diff --git a/src/Client/Project.php b/src/Client/Project.php index 46b163a..9b78833 100644 --- a/src/Client/Project.php +++ b/src/Client/Project.php @@ -19,14 +19,15 @@ public function __construct( } /** - * Fetch the moderation thread of this project from the API (requires authentication) + * Fetch the moderation thread of this project (requires authentication) + * This sends a request to the Modrinth API every time it is called. * * Not part of {@link ProjectTrait} because search results do not carry a thread id. * * @return Thread * @throws ApiException */ - public function getThread(): Thread + public function fetchThread(): Thread { return $this->client->getThread($this->getThreadId()); } diff --git a/src/Client/ProjectTrait.php b/src/Client/ProjectTrait.php index 7981ca7..37f093e 100644 --- a/src/Client/ProjectTrait.php +++ b/src/Client/ProjectTrait.php @@ -19,17 +19,19 @@ abstract protected function getId(): string; abstract protected function getClient(): ModrinthAPIClient; /** - * Get all dependencies of this project + * Fetch all dependencies of this project + * This sends a request to the Modrinth API every time it is called. * @return ProjectDependencies * @throws ApiException */ - public function getDependencies(): ProjectDependencies + public function fetchDependencies(): ProjectDependencies { return $this->getClient()->getProjectDependencies($this->getId()); } /** - * Get all versions of this project + * Fetch all versions of this project + * This sends a request to the Modrinth API every time it is called. * @param string[]|null $loaders only show versions for any of these loaders * @param string[]|null $gameVersions * @param bool|null $featured @@ -48,11 +50,12 @@ public function fetchProjectVersions( } /** - * Get the members of this project + * Fetch the members of this project + * This sends a request to the Modrinth API every time it is called. * @return TeamMember[] * @throws ApiException */ - public function getMembers(): array + public function fetchMembers(): array { return $this->getClient()->getProjectMembers($this->getId()); } diff --git a/src/Client/SearchProject.php b/src/Client/SearchProject.php index c6f891e..7e9ed92 100644 --- a/src/Client/SearchProject.php +++ b/src/Client/SearchProject.php @@ -24,17 +24,19 @@ public function __construct( } /** - * Fetch the full project from the API + * Fetch the full project + * This sends a request to the Modrinth API every time it is called. * @return Project * @throws ApiException */ - public function getFullProject(): Project + public function fetchFullProject(): Project { return $this->client->getProject($this->getProjectId()); } /** - * Fetch the author of this project from the API. + * Fetch the author of this project + * This sends a request to the Modrinth API every time it is called. * * Named differently from the inherited {@link ProjectResult::getAuthor()}, which * returns the author's username without requesting anything. diff --git a/src/Client/TeamMember.php b/src/Client/TeamMember.php index eb3c4aa..1496b1f 100644 --- a/src/Client/TeamMember.php +++ b/src/Client/TeamMember.php @@ -25,11 +25,12 @@ public function getUser(): User } /** - * Fetch all members of the team this member belongs to from the API + * Fetch all members of the team this member belongs to + * This sends a request to the Modrinth API every time it is called. * @return TeamMember[] * @throws ApiException */ - public function getTeamMembers(): array + public function fetchTeamMembers(): array { return $this->client->getTeamMembers($this->getTeamId()); } diff --git a/src/Client/Threads/Report.php b/src/Client/Threads/Report.php index 7c1cca5..92361fb 100644 --- a/src/Client/Threads/Report.php +++ b/src/Client/Threads/Report.php @@ -29,12 +29,13 @@ public function getItemTypeEnum(): ReportItemType } /** - * Fetch the full project from the API if the report is a project report + * Fetch the reported project if the report is a project report + * This sends a request to the Modrinth API every time it is called. * @return Project * @throws ApiException * @throws Exception */ - public function getProject(): Project + public function fetchProject(): Project { if ($this->getItemTypeEnum() !== ReportItemType::PROJECT) { throw new Exception("Report is not a project report"); @@ -44,12 +45,13 @@ public function getProject(): Project } /** - * Fetch the full user from the API if the report is a user report + * Fetch the reported user if the report is a user report + * This sends a request to the Modrinth API every time it is called. * @return User * @throws ApiException * @throws Exception */ - public function getUser(): User + public function fetchUser(): User { if ($this->getItemTypeEnum() !== ReportItemType::USER) { throw new Exception("Report is not a user report"); @@ -59,12 +61,13 @@ public function getUser(): User } /** - * Fetch the full version from the API if the report is a version report + * Fetch the reported version if the report is a version report + * This sends a request to the Modrinth API every time it is called. * @return Version * @throws ApiException * @throws Exception */ - public function getVersion(): Version + public function fetchVersion(): Version { if ($this->getItemTypeEnum() !== ReportItemType::VERSION) { throw new Exception("Report is not a version report"); @@ -74,11 +77,12 @@ public function getVersion(): Version } /** - * Fetch the thread of this report from the API (requires authentication) + * Fetch the thread of this report (requires authentication) + * This sends a request to the Modrinth API every time it is called. * @return Thread * @throws ApiException */ - public function getThread(): Thread + public function fetchThread(): Thread { return $this->client->getThread($this->getThreadId()); } diff --git a/src/Client/Threads/Thread.php b/src/Client/Threads/Thread.php index 1a842cf..a8ee7da 100644 --- a/src/Client/Threads/Thread.php +++ b/src/Client/Threads/Thread.php @@ -19,11 +19,13 @@ public function __construct( } /** - * Fetch the full project from the API if the thread has a project id + * Fetch the project of this thread + * This sends a request to the Modrinth API every time it is called. + * Returns null if the thread has no project id. * @return Project|null * @throws ApiException */ - public function getProject(): ?Project + public function fetchProject(): ?Project { if ($id = $this->getProjectId()) { return $this->client->getProject($id); @@ -33,11 +35,13 @@ public function getProject(): ?Project } /** - * Fetch the full report from the API if the thread has a report id + * Fetch the report of this thread + * This sends a request to the Modrinth API every time it is called. + * Returns null if the thread has no report id. * @return Report|null * @throws ApiException */ - public function getReport(): ?Report + public function fetchReport(): ?Report { if ($id = $this->getReportId()) { return $this->client->getReport($id); diff --git a/src/Client/Threads/ThreadMessage.php b/src/Client/Threads/ThreadMessage.php index fc49266..a57e03c 100644 --- a/src/Client/Threads/ThreadMessage.php +++ b/src/Client/Threads/ThreadMessage.php @@ -28,12 +28,13 @@ public function getThread(): Thread } /** - * Fetch the user that wrote this message from the API. + * Fetch the user that wrote this message + * This sends a request to the Modrinth API every time it is called. * Returns null if the message has no author, e.g. for system messages. * @return User|null * @throws ApiException */ - public function getAuthor(): ?User + public function fetchAuthor(): ?User { if ($this->getAuthorId() === null) { return null; diff --git a/src/Client/User.php b/src/Client/User.php index 91f5e33..f7b7caf 100644 --- a/src/Client/User.php +++ b/src/Client/User.php @@ -17,41 +17,45 @@ public function __construct( } /** - * Get the user's projects + * Fetch the user's projects + * This sends a request to the Modrinth API every time it is called. * @return Project[] * @throws ApiException */ - public function getProjects(): array + public function fetchProjects(): array { return $this->client->getUserProjects($this->getId()); } /** - * Get the user's notifications (requires authentication) + * Fetch the user's notifications (requires authentication) + * This sends a request to the Modrinth API every time it is called. * @return Notification[] * @throws ApiException */ - public function getNotifications(): array + public function fetchNotifications(): array { return $this->client->getUserNotifications($this->getId()); } /** - * Get the user projects this user follows (requires authentication) + * Fetch the projects this user follows (requires authentication) + * This sends a request to the Modrinth API every time it is called. * @return Project[] * @throws ApiException */ - public function getFollowedProjects(): array + public function fetchFollowedProjects(): array { return $this->client->getFollowedProjects($this->getId()); } /** - * Get the user's payout history (requires authentication) + * Fetch the user's payout history (requires authentication) + * This sends a request to the Modrinth API every time it is called. * @return UserPayoutHistory * @throws ApiException */ - public function getPayoutHistory(): UserPayoutHistory + public function fetchPayoutHistory(): UserPayoutHistory { return $this->client->getPayoutHistory($this->getId()); } diff --git a/src/Client/Version.php b/src/Client/Version.php index 45b5849..5cce210 100644 --- a/src/Client/Version.php +++ b/src/Client/Version.php @@ -17,21 +17,23 @@ public function __construct( } /** - * Fetch the full project from the API + * Fetch the project of this version + * This sends a request to the Modrinth API every time it is called. * @return Project * @throws ApiException */ - public function getProject(): Project + public function fetchProject(): Project { return $this->client->getProject($this->getProjectId()); } /** - * Fetch the user that published this version from the API + * Fetch the user that published this version + * This sends a request to the Modrinth API every time it is called. * @return User * @throws ApiException */ - public function getAuthor(): User + public function fetchAuthor(): User { return $this->client->getUser($this->getAuthorId()); } diff --git a/src/Client/VersionDependency.php b/src/Client/VersionDependency.php index 36dac53..f34b355 100644 --- a/src/Client/VersionDependency.php +++ b/src/Client/VersionDependency.php @@ -16,11 +16,13 @@ public function __construct( } /** - * Get the project of this dependency (if available) + * Fetch the project of this dependency + * This sends a request to the Modrinth API every time it is called. + * Returns null if the dependency has no project id. * @return Project|null * @throws ApiException */ - public function getProject(): ?Project + public function fetchProject(): ?Project { if ($this->getProjectId() === null) { return null; @@ -30,11 +32,13 @@ public function getProject(): ?Project } /** - * Get the version of this dependency (if available) + * Fetch the version of this dependency + * This sends a request to the Modrinth API every time it is called. + * Returns null if the dependency has no version id. * @return Version|null * @throws ApiException */ - public function getVersion(): ?Version + public function fetchVersion(): ?Version { if ($this->getVersionId() === null) { return null; diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index d9af96e..467f554 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -185,7 +185,7 @@ public function testGetProject(): void public function testGetProjectVersionsAndDependencies(): void { $project = $this->apiClient->getProject("mclogs"); - $this->assertNotEmpty($project->getDependencies()); + $this->assertNotEmpty($project->fetchDependencies()); $this->assertNotEmpty($project->getVersions()); $this->assertNotEmpty($project->getVersions( ["forge"], @@ -228,7 +228,7 @@ public function testGetVersion(): void $version = $this->apiClient->getVersion("moYTqMH3"); $this->assertNotNull($version); $this->assertEquals("VPo0otUH", $version->getProjectId()); - $this->assertEquals("VPo0otUH", $version->getProject()->getId()); + $this->assertEquals("VPo0otUH", $version->fetchProject()->getId()); } public function testGetVersions(): void @@ -239,7 +239,7 @@ public function testGetVersions(): void foreach ($versions as $version) { $this->assertNotNull($version); $this->assertEquals("VPo0otUH", $version->getProjectId()); - $this->assertEquals("VPo0otUH", $version->getProject()->getId()); + $this->assertEquals("VPo0otUH", $version->fetchProject()->getId()); } } @@ -285,7 +285,7 @@ public function testGetLatestVersionFromHash(): void $this->assertNotNull($version); $this->assertEquals("VPo0otUH", $version->getProjectId()); $this->assertEquals( - $version->getProject()->fetchProjectVersions(["spigot"], ["1.20.1"])[0]->getId(), + $version->fetchProject()->fetchProjectVersions(["spigot"], ["1.20.1"])[0]->getId(), $version->getId(), ); } @@ -305,7 +305,7 @@ public function testGetLatestVersionsFromHashes(): void $this->assertNotNull($version); $this->assertEquals("VPo0otUH", $version->getProjectId()); $this->assertEquals( - $version->getProject()->fetchProjectVersions(["spigot"], ["1.20.1"])[0]->getId(), + $version->fetchProject()->fetchProjectVersions(["spigot"], ["1.20.1"])[0]->getId(), $version->getId(), ); } @@ -316,7 +316,7 @@ public function testGetUser(): void $user = $this->apiClient->getUser("Julian"); $this->assertNotNull($user); $this->assertEquals("Julian", $user->getUsername()); - $projects = $user->getProjects(); + $projects = $user->fetchProjects(); $this->assertNotNull($projects); } @@ -548,14 +548,14 @@ public function testProjectMembersAndDependenciesFromProject(): void { $project = $this->apiClient->getProject("mclogs"); - $members = $project->getMembers(); + $members = $project->fetchMembers(); $this->assertNotEmpty($members); foreach ($members as $member) { $this->assertInstanceOf(TeamMember::class, $member); $this->assertNotEmpty($member->getUser()->getUsername()); } - $this->assertInstanceOf(ProjectDependencies::class, $project->getDependencies()); + $this->assertInstanceOf(ProjectDependencies::class, $project->fetchDependencies()); } public function testGetLatestVersionFromHashWithVersionTypes(): void @@ -741,7 +741,7 @@ public function testGetVersionAuthor(): void { $version = $this->apiClient->getVersion("moYTqMH3"); - $author = $version->getAuthor(); + $author = $version->fetchAuthor(); $this->assertInstanceOf(User::class, $author); $this->assertEquals($version->getAuthorId(), $author->getId()); $this->assertNotEmpty($author->getUsername()); @@ -790,7 +790,7 @@ public function testGetTeamMembersFromTeamMember(): void $members = $this->apiClient->getProjectMembers("VPo0otUH"); $this->assertNotEmpty($members); - $teamMembers = $members[0]->getTeamMembers(); + $teamMembers = $members[0]->fetchTeamMembers(); $this->assertNotEmpty($teamMembers); foreach ($teamMembers as $teamMember) { $this->assertInstanceOf(TeamMember::class, $teamMember); @@ -804,7 +804,7 @@ public function testSearchProjectResultsCanBeExpanded(): void $this->assertValidProjectList($projects); $searchProject = $projects[0]; - $fullProject = $searchProject->getFullProject(); + $fullProject = $searchProject->fetchFullProject(); $this->assertEquals($searchProject->getProjectId(), $fullProject->getId()); } } diff --git a/tests/Unit/Client/Models/NotificationTest.php b/tests/Unit/Client/Models/NotificationTest.php index aaff493..ef533c9 100644 --- a/tests/Unit/Client/Models/NotificationTest.php +++ b/tests/Unit/Client/Models/NotificationTest.php @@ -12,7 +12,7 @@ class NotificationTest extends TestCase { - public function testGetUserReturnsCorrectUser(): void + public function testFetchUserReturnsCorrectUser(): void { // Here we must mock the client, because it requests the user from the API to get all details $handler = new MockHandler([ @@ -24,7 +24,7 @@ public function testGetUserReturnsCorrectUser(): void $notification = new Notification($client, $this->getExampleNotificationModel()); // Dc7EYhxG -> https://modrinth.com/user/Prospector $user = $client->getUser("Dc7EYhxG"); - $this->assertEquals($user, $notification->getUser()); + $this->assertEquals($user, $notification->fetchUser()); } protected function getExampleNotificationModel(): \Aternos\ModrinthApi\Model\Notification diff --git a/tests/Unit/Client/Models/ProjectTest.php b/tests/Unit/Client/Models/ProjectTest.php index da1adfe..ba07cf6 100644 --- a/tests/Unit/Client/Models/ProjectTest.php +++ b/tests/Unit/Client/Models/ProjectTest.php @@ -31,12 +31,12 @@ public function testConstructorCopiesTheModelData(): void $this->assertEquals($model->getTitle(), $project->getTitle()); } - public function testGetDependencies(): void + public function testFetchDependencies(): void { $client = $this->createClient([$this->fixtureResponse("get_project_dependencies_response")]); $project = new Project($client, $this->getExampleProjectModel()); - $dependencies = $project->getDependencies(); + $dependencies = $project->fetchDependencies(); $this->assertInstanceOf(ProjectDependencies::class, $dependencies); $this->assertNotEmpty($dependencies->getProjects()); $this->assertNotEmpty($dependencies->getVersions()); @@ -74,24 +74,24 @@ public function testFetchProjectVersionsPassesFilters(): void $this->assertEquals("false", $query["include_changelog"]); } - public function testGetThread(): void + public function testFetchThread(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_thread_response")]); $project = new Project($client, $this->getExampleProjectModel()); - $thread = $project->getThread(); + $thread = $project->fetchThread(); $this->assertInstanceOf(Thread::class, $thread); $this->assertEquals("Ba1AaBbC", $thread->getId()); $this->assertRequest("GET", "/v2/thread/" . $this->getExampleProjectModel()->getThreadId()); $this->assertRequestAuthenticated(); } - public function testGetMembers(): void + public function testFetchMembers(): void { $client = $this->createClient([$this->fixtureResponse("get_team_members_response")]); $project = new Project($client, $this->getExampleProjectModel()); - $members = $project->getMembers(); + $members = $project->fetchMembers(); $this->assertCount(1, $members); $this->assertInstanceOf(TeamMember::class, $members[0]); $this->assertEquals("Owner", $members[0]->getRole()); diff --git a/tests/Unit/Client/Models/SearchProjectTest.php b/tests/Unit/Client/Models/SearchProjectTest.php index 5b17089..b120306 100644 --- a/tests/Unit/Client/Models/SearchProjectTest.php +++ b/tests/Unit/Client/Models/SearchProjectTest.php @@ -16,7 +16,7 @@ class SearchProjectTest extends TestCase { - public function testGetFullProjectReturnsInstanceOfProject(): void + public function testFetchFullProjectReturnsInstanceOfProject(): void { $projectResultModel = $this->getExampleProjectResultModel(); // Here we must mock the client, because it requests the user from the API to get all details @@ -26,10 +26,10 @@ public function testGetFullProjectReturnsInstanceOfProject(): void $client = new ModrinthAPIClient(null, null, new Client(['handler' => HandlerStack::create($handler)])); $searchProject = new SearchProject($client, $projectResultModel); - $this->assertInstanceOf(Project::class, $searchProject->getFullProject()); + $this->assertInstanceOf(Project::class, $searchProject->fetchFullProject()); } - public function testGetFullProjectRequestsTheProjectId(): void + public function testFetchFullProjectRequestsTheProjectId(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/../Fixtures/get_project_response.json")) @@ -40,13 +40,13 @@ public function testGetFullProjectRequestsTheProjectId(): void $client = new ModrinthAPIClient(null, null, new Client(['handler' => $stack])); $searchProject = new SearchProject($client, $this->getExampleProjectResultModel()); - $searchProject->getFullProject(); + $searchProject->fetchFullProject(); $this->assertCount(1, $requests); $this->assertEquals("/v2/project/P7dR8mSH", $requests[0]["request"]->getUri()->getPath()); } - public function testGetDependenciesUsesTheProjectId(): void + public function testFetchDependenciesUsesTheProjectId(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/../Fixtures/get_project_dependencies_response.json")) @@ -57,7 +57,7 @@ public function testGetDependenciesUsesTheProjectId(): void $client = new ModrinthAPIClient(null, null, new Client(['handler' => $stack])); $searchProject = new SearchProject($client, $this->getExampleProjectResultModel()); - $this->assertNotEmpty($searchProject->getDependencies()->getProjects()); + $this->assertNotEmpty($searchProject->fetchDependencies()->getProjects()); $this->assertEquals("/v2/project/P7dR8mSH/dependencies", $requests[0]["request"]->getUri()->getPath()); } diff --git a/tests/Unit/Client/Models/TeamMemberTest.php b/tests/Unit/Client/Models/TeamMemberTest.php index 59a516e..4feb379 100644 --- a/tests/Unit/Client/Models/TeamMemberTest.php +++ b/tests/Unit/Client/Models/TeamMemberTest.php @@ -36,26 +36,26 @@ public function testGetUserReturnsAClientUserWithoutRequest(): void $this->assertRequestCount(0); } - public function testGetTeamMembers(): void + public function testFetchTeamMembers(): void { $client = $this->createClient([$this->fixtureResponse("get_team_members_response")]); $member = new TeamMember($client, $this->getExampleTeamMemberModel()); - $members = $member->getTeamMembers(); + $members = $member->fetchTeamMembers(); $this->assertCount(1, $members); $this->assertInstanceOf(TeamMember::class, $members[0]); $this->assertEquals("Owner", $members[0]->getRole()); $this->assertRequest("GET", "/v2/team/ThaUQrOs/members"); } - public function testGetUserCanRequestTheUsersProjects(): void + public function testGetUserCanFetchTheUsersProjects(): void { $client = $this->createClient([ $this->jsonResponse([$this->fixtureData("get_project_response")]), ]); $member = new TeamMember($client, $this->getExampleTeamMemberModel()); - $this->assertCount(1, $member->getUser()->getProjects()); + $this->assertCount(1, $member->getUser()->fetchProjects()); $this->assertRequest("GET", "/v2/user/Dc7EYhxG/projects"); } } diff --git a/tests/Unit/Client/Models/UserTest.php b/tests/Unit/Client/Models/UserTest.php index fcf2ae8..695e3ef 100644 --- a/tests/Unit/Client/Models/UserTest.php +++ b/tests/Unit/Client/Models/UserTest.php @@ -25,53 +25,53 @@ public function testConstructorCopiesTheModelData(): void $this->assertEquals($model->getUsername(), $user->getUsername()); } - public function testGetProjects(): void + public function testFetchProjects(): void { $client = $this->createClient([ $this->jsonResponse([$this->fixtureData("get_project_response")]), ]); $user = new User($client, $this->getExampleUserModel()); - $projects = $user->getProjects(); + $projects = $user->fetchProjects(); $this->assertCount(1, $projects); $this->assertInstanceOf(Project::class, $projects[0]); $this->assertRequest("GET", "/v2/user/Dc7EYhxG/projects"); } - public function testGetNotifications(): void + public function testFetchNotifications(): void { $client = $this->createAuthenticatedClient([ $this->jsonResponse([$this->fixtureData("get_notification_response")]), ]); $user = new User($client, $this->getExampleUserModel()); - $notifications = $user->getNotifications(); + $notifications = $user->fetchNotifications(); $this->assertCount(1, $notifications); $this->assertInstanceOf(Notification::class, $notifications[0]); $this->assertRequest("GET", "/v2/user/Dc7EYhxG/notifications"); $this->assertRequestAuthenticated(); } - public function testGetFollowedProjects(): void + public function testFetchFollowedProjects(): void { $client = $this->createAuthenticatedClient([ $this->jsonResponse([$this->fixtureData("get_project_response")]), ]); $user = new User($client, $this->getExampleUserModel()); - $projects = $user->getFollowedProjects(); + $projects = $user->fetchFollowedProjects(); $this->assertCount(1, $projects); $this->assertInstanceOf(Project::class, $projects[0]); $this->assertRequest("GET", "/v2/user/Dc7EYhxG/follows"); $this->assertRequestAuthenticated(); } - public function testGetPayoutHistory(): void + public function testFetchPayoutHistory(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_payout_history_response")]); $user = new User($client, $this->getExampleUserModel()); - $history = $user->getPayoutHistory(); + $history = $user->fetchPayoutHistory(); $this->assertInstanceOf(UserPayoutHistory::class, $history); $this->assertEquals("78.90", $history->getLastMonth()); $this->assertRequest("GET", "/v2/user/Dc7EYhxG/payouts"); diff --git a/tests/Unit/Client/Models/VersionDependencyTest.php b/tests/Unit/Client/Models/VersionDependencyTest.php index af188d9..272b675 100644 --- a/tests/Unit/Client/Models/VersionDependencyTest.php +++ b/tests/Unit/Client/Models/VersionDependencyTest.php @@ -20,41 +20,41 @@ protected function getExampleDependencyModel(int $index = 0): VersionDependencyM return $this->fixtureModel("get_version_response", VersionModel::class)->getDependencies()[$index]; } - public function testGetProject(): void + public function testFetchProject(): void { $client = $this->createClient([$this->fixtureResponse("get_project_response")]); $dependency = new VersionDependency($client, $this->getExampleDependencyModel()); - $project = $dependency->getProject(); + $project = $dependency->fetchProject(); $this->assertInstanceOf(Project::class, $project); $this->assertRequest("GET", "/v2/project/AANobbMI"); } - public function testGetProjectReturnsNullWithoutProjectId(): void + public function testFetchProjectReturnsNullWithoutProjectId(): void { $client = $this->createClient(); $dependency = new VersionDependency($client, $this->getExampleDependencyModel(1)); - $this->assertNull($dependency->getProject()); + $this->assertNull($dependency->fetchProject()); $this->assertRequestCount(0); } - public function testGetVersion(): void + public function testFetchVersion(): void { $client = $this->createClient([$this->fixtureResponse("get_version_response")]); $dependency = new VersionDependency($client, $this->getExampleDependencyModel()); - $version = $dependency->getVersion(); + $version = $dependency->fetchVersion(); $this->assertInstanceOf(Version::class, $version); $this->assertRequest("GET", "/v2/version/vgceLbdH"); } - public function testGetVersionReturnsNullWithoutVersionId(): void + public function testFetchVersionReturnsNullWithoutVersionId(): void { $client = $this->createClient(); $dependency = new VersionDependency($client, $this->getExampleDependencyModel(1)); - $this->assertNull($dependency->getVersion()); + $this->assertNull($dependency->fetchVersion()); $this->assertRequestCount(0); } } diff --git a/tests/Unit/Client/Models/VersionTest.php b/tests/Unit/Client/Models/VersionTest.php index 1ceb39b..64e157d 100644 --- a/tests/Unit/Client/Models/VersionTest.php +++ b/tests/Unit/Client/Models/VersionTest.php @@ -25,23 +25,23 @@ public function testConstructorCopiesTheModelData(): void $this->assertEquals($model->getVersionNumber(), $version->getVersionNumber()); } - public function testGetProject(): void + public function testFetchProject(): void { $client = $this->createClient([$this->fixtureResponse("get_project_response")]); $version = new Version($client, $this->getExampleVersionModel()); - $project = $version->getProject(); + $project = $version->fetchProject(); $this->assertInstanceOf(Project::class, $project); $this->assertEquals("modmenu", $project->getSlug()); $this->assertRequest("GET", "/v2/project/VPo0otUH"); } - public function testGetAuthor(): void + public function testFetchAuthor(): void { $client = $this->createClient([$this->fixtureResponse("get_user_response")]); $version = new Version($client, $this->getExampleVersionModel()); - $author = $version->getAuthor(); + $author = $version->fetchAuthor(); $this->assertInstanceOf(User::class, $author); $this->assertEquals("Prospector", $author->getUsername()); $this->assertRequest("GET", "/v2/user/b1AIbOxO"); diff --git a/tests/Unit/Client/Threads/ReportTest.php b/tests/Unit/Client/Threads/ReportTest.php index 2b343c5..c4ca6ac 100644 --- a/tests/Unit/Client/Threads/ReportTest.php +++ b/tests/Unit/Client/Threads/ReportTest.php @@ -56,66 +56,66 @@ public function testGetItemTypeEnum(): void ); } - public function testGetProject(): void + public function testFetchProject(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_project_response")]); $report = new Report($client, $this->getExampleReportModel("project", "mOgUt4GM")); - $this->assertInstanceOf(Project::class, $report->getProject()); + $this->assertInstanceOf(Project::class, $report->fetchProject()); $this->assertRequest("GET", "/v2/project/mOgUt4GM"); } - public function testGetProjectThrowsForOtherReportTypes(): void + public function testFetchProjectThrowsForOtherReportTypes(): void { $report = new Report($this->createClient(), $this->getExampleReportModel("user")); $this->expectException(Exception::class); $this->expectExceptionMessage("Report is not a project report"); - $report->getProject(); + $report->fetchProject(); } - public function testGetUser(): void + public function testFetchUser(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_user_response")]); $report = new Report($client, $this->getExampleReportModel("user", "Dc7EYhxG")); - $this->assertInstanceOf(User::class, $report->getUser()); + $this->assertInstanceOf(User::class, $report->fetchUser()); $this->assertRequest("GET", "/v2/user/Dc7EYhxG"); } - public function testGetUserThrowsForOtherReportTypes(): void + public function testFetchUserThrowsForOtherReportTypes(): void { $report = new Report($this->createClient(), $this->getExampleReportModel("project")); $this->expectException(Exception::class); $this->expectExceptionMessage("Report is not a user report"); - $report->getUser(); + $report->fetchUser(); } - public function testGetVersion(): void + public function testFetchVersion(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_version_response")]); $report = new Report($client, $this->getExampleReportModel("version", "moYTqMH3")); - $this->assertInstanceOf(Version::class, $report->getVersion()); + $this->assertInstanceOf(Version::class, $report->fetchVersion()); $this->assertRequest("GET", "/v2/version/moYTqMH3"); } - public function testGetVersionThrowsForOtherReportTypes(): void + public function testFetchVersionThrowsForOtherReportTypes(): void { $report = new Report($this->createClient(), $this->getExampleReportModel("project")); $this->expectException(Exception::class); $this->expectExceptionMessage("Report is not a version report"); - $report->getVersion(); + $report->fetchVersion(); } - public function testGetThread(): void + public function testFetchThread(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_thread_response")]); $report = new Report($client, $this->getExampleReportModel()); - $thread = $report->getThread(); + $thread = $report->fetchThread(); $this->assertInstanceOf(Thread::class, $thread); $this->assertEquals("Ba1AaBbC", $thread->getId()); $this->assertRequest("GET", "/v2/thread/Ba1AaBbC"); diff --git a/tests/Unit/Client/Threads/ThreadMessageTest.php b/tests/Unit/Client/Threads/ThreadMessageTest.php index b09c7b1..f40c074 100644 --- a/tests/Unit/Client/Threads/ThreadMessageTest.php +++ b/tests/Unit/Client/Threads/ThreadMessageTest.php @@ -37,24 +37,24 @@ public function testGetThread(): void $this->assertSame($thread, $thread->getMessages()[0]->getThread()); } - public function testGetAuthor(): void + public function testFetchAuthor(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_user_response")]); $message = $this->getExampleThread($client)->getMessages()[0]; - $author = $message->getAuthor(); + $author = $message->fetchAuthor(); $this->assertInstanceOf(User::class, $author); $this->assertEquals("Prospector", $author->getUsername()); $this->assertRequest("GET", "/v2/user/b1AIbOxO"); } - public function testGetAuthorReturnsNullWithoutAuthorId(): void + public function testFetchAuthorReturnsNullWithoutAuthorId(): void { $client = $this->createAuthenticatedClient(); $message = $this->getExampleThread($client)->getMessages()[0]; $message->setAuthorId(null); - $this->assertNull($message->getAuthor()); + $this->assertNull($message->fetchAuthor()); $this->assertRequestCount(0); } diff --git a/tests/Unit/Client/Threads/ThreadTest.php b/tests/Unit/Client/Threads/ThreadTest.php index 98dc17d..ec6d404 100644 --- a/tests/Unit/Client/Threads/ThreadTest.php +++ b/tests/Unit/Client/Threads/ThreadTest.php @@ -29,41 +29,41 @@ public function testConstructorCopiesTheModelData(): void $this->assertEquals($model->getProjectId(), $thread->getProjectId()); } - public function testGetProject(): void + public function testFetchProject(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_project_response")]); $thread = new Thread($client, $this->getExampleThreadModel()); - $this->assertInstanceOf(Project::class, $thread->getProject()); + $this->assertInstanceOf(Project::class, $thread->fetchProject()); $this->assertRequest("GET", "/v2/project/VPo0otUH"); } - public function testGetProjectReturnsNullWithoutProjectId(): void + public function testFetchProjectReturnsNullWithoutProjectId(): void { $client = $this->createAuthenticatedClient(); $thread = new Thread($client, $this->getExampleThreadModel("get_thread_without_references_response")); - $this->assertNull($thread->getProject()); + $this->assertNull($thread->fetchProject()); $this->assertRequestCount(0); } - public function testGetReport(): void + public function testFetchReport(): void { $client = $this->createAuthenticatedClient([$this->fixtureResponse("get_report_response")]); $thread = new Thread($client, $this->getExampleThreadModel()); - $report = $thread->getReport(); + $report = $thread->fetchReport(); $this->assertInstanceOf(Report::class, $report); $this->assertEquals("RepOrt01", $report->getId()); $this->assertRequest("GET", "/v2/report/RepOrt01"); } - public function testGetReportReturnsNullWithoutReportId(): void + public function testFetchReportReturnsNullWithoutReportId(): void { $client = $this->createAuthenticatedClient(); $thread = new Thread($client, $this->getExampleThreadModel("get_thread_without_references_response")); - $this->assertNull($thread->getReport()); + $this->assertNull($thread->fetchReport()); $this->assertRequestCount(0); }