From ed1f25aad77f8055b5fcb37fc031811b555346ef Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Fri, 16 Oct 2026 17:37:25 +0200 Subject: [PATCH 1/2] extend the generated models in the wrappers --- README.md | 62 +++++++++++++----------- src/Client/Author.php | 19 +++++--- src/Client/Project.php | 24 +++++---- src/Client/Version.php | 17 ++++--- tests/Integration/Client/ClientTest.php | 28 +++++------ tests/Integration/Client/ProjectTest.php | 22 ++++----- tests/TestCase.php | 52 ++++++++++---------- tests/Unit/Client/AuthorTest.php | 23 +++++++-- tests/Unit/Client/ClientTest.php | 20 ++++---- tests/Unit/Client/ProjectTest.php | 47 ++++++++++++++---- tests/Unit/Client/VersionTest.php | 20 +++++++- 11 files changed, 206 insertions(+), 128 deletions(-) diff --git a/README.md b/README.md index e389e3e..ac71712 100644 --- a/README.md +++ b/README.md @@ -84,14 +84,14 @@ use Aternos\SpigotApi\Client\SortDirection; $projects = $spigotClient->listProjects(1); foreach ($projects as $project) { - // wrappers expose underlying model via getData() - echo $project->getData()->getTitle() . PHP_EOL; + // wrappers extend the generated models, so all getters can be used directly + echo $project->getTitle() . PHP_EOL; } $projects = $projects->getNextPage(); foreach ($projects as $project) { - echo $project->getData()->getTitle() . PHP_EOL; + echo $project->getTitle() . PHP_EOL; } // list the most downloaded projects @@ -118,14 +118,14 @@ use Aternos\SpigotApi\Client\SortDirection; $projects = $spigotClient->listProjectsForCategory(Category::SPIGOT, 1); foreach ($projects as $project) { - // wrappers expose underlying model via getData() - echo $project->getData()->getTitle() . PHP_EOL; + // wrappers extend the generated models, so all getters can be used directly + echo $project->getTitle() . PHP_EOL; } $projects = $projects->getNextPage(); foreach ($projects as $project) { - echo $project->getData()->getTitle() . PHP_EOL; + echo $project->getTitle() . PHP_EOL; } // list the most recently updated projects in a category @@ -145,10 +145,13 @@ To get a single project (resource) by its numeric id, use `getProject()`. // get a specific project (by numeric id) $project = $spigotClient->getProject(2); -// get data from the wrapper -$id = $project->getData()->getId(); -$title = $project->getData()->getTitle(); -$description = $project->getData()->getDescription(); +// the wrapper extends the generated model, so all getters of the model can be used directly +$id = $project->getId(); +$title = $project->getTitle(); +$description = $project->getDescription(); + +// the category as an Aternos\SpigotApi\Client\Category enum +$category = $project->getCategoryType(); ``` ### More information @@ -167,10 +170,13 @@ $versions = $project->getVersions(); // get the newest versions first $versions = $project->getVersions(1, VersionOrder::POST_DATE, SortDirection::DESC); -// get the author -$author = $project->getAuthor(); +// fetch the full author from the API +$author = $project->fetchAuthor(); ``` +`$project->getAuthor()` and `$project->getCategory()` are the getters of the generated model. +They only contain the id and username of the author and the id, title and description of the category, and do not send a request. + ## Authors ### getAuthor() @@ -185,12 +191,12 @@ To get a single author by its numeric id, use `getAuthor()`. $author = $spigotClient->getAuthor(1); // get data from the wrapper -$id = $author->getData()->getId(); -$username = $author->getData()->getUsername(); -$resources = $author->getData()->getResourceCount(); -$identities = $author->getData()->getIdentities(); -$avatarUrl = $author->getData()->getAvatar(); -$activity = $author->getData()->getLastActivity(); +$id = $author->getId(); +$username = $author->getUsername(); +$resources = $author->getResourceCount(); +$identities = $author->getIdentities(); +$avatarUrl = $author->getAvatar(); +$activity = $author->getLastActivity(); ``` ### findAuthor() @@ -205,12 +211,12 @@ To find an author by username, use `findAuthor()`. $author = $spigotClient->findAuthor("md_5"); // get data from the wrapper -$id = $author->getData()->getId(); -$username = $author->getData()->getUsername(); -$resources = $author->getData()->getResourceCount(); -$identities = $author->getData()->getIdentities(); -$avatarUrl = $author->getData()->getAvatar(); -$activity = $author->getData()->getLastActivity(); +$id = $author->getId(); +$username = $author->getUsername(); +$resources = $author->getResourceCount(); +$identities = $author->getIdentities(); +$avatarUrl = $author->getAvatar(); +$activity = $author->getLastActivity(); ``` ### More information @@ -237,7 +243,7 @@ To list all projects for an author (paginated), use `getAuthorProjects()`. // list all projects from Luck $projects = $spigotClient->getAuthorProjects(100356); foreach ($projects as $project) { - echo $project->getData()->getTitle() . PHP_EOL; + echo $project->getTitle() . PHP_EOL; } ``` @@ -260,7 +266,7 @@ use Aternos\SpigotApi\Client\VersionOrder; $versions = $spigotClient->getProjectVersions(2); foreach ($versions as $version) { - echo $version->getData()->getTitle() . PHP_EOL; + echo $version->getTitle() . PHP_EOL; } // list the newest versions first @@ -277,8 +283,8 @@ To fetch a specific update by its id, use `getVersion()`. ```php $version = $spigotClient->getVersion(352711); -echo $version->getData()->getTitle() . PHP_EOL; -echo $version->getData()->getMessage() . PHP_EOL; +echo $version->getTitle() . PHP_EOL; +echo $version->getMessage() . PHP_EOL; ``` ### More information diff --git a/src/Client/Author.php b/src/Client/Author.php index 3338196..ebf467f 100644 --- a/src/Client/Author.php +++ b/src/Client/Author.php @@ -4,21 +4,26 @@ use Aternos\SpigotApi\ApiException; use Aternos\SpigotApi\Client\List\PaginatedAuthorProjectList; -use Aternos\SpigotApi\Model\Author as SpigotAuthor; +use Aternos\SpigotApi\Model\Author as AuthorModel; -class Author +class Author extends AuthorModel { public function __construct( protected SpigotAPIClient $client, - protected SpigotAuthor $data + AuthorModel $data ) { + parent::__construct($data->container); } - public function getData(): SpigotAuthor + /** + * @deprecated The author extends the generated model now, so its getters can be used directly. + * @return AuthorModel + */ + public function getData(): AuthorModel { - return $this->data; + return $this; } /** @@ -28,7 +33,7 @@ public function getData(): SpigotAuthor */ public function getId(): int { - return intval($this->data->getId()); + return intval(parent::getId()); } /** @@ -40,4 +45,4 @@ public function getProjects(): PaginatedAuthorProjectList { return $this->client->getAuthorProjects($this->getId()); } -} \ No newline at end of file +} diff --git a/src/Client/Project.php b/src/Client/Project.php index 891eefe..705b1fb 100644 --- a/src/Client/Project.php +++ b/src/Client/Project.php @@ -6,19 +6,24 @@ use Aternos\SpigotApi\Client\List\PaginatedVersionList; use Aternos\SpigotApi\Model\Resource; -class Project +class Project extends Resource { public function __construct( protected SpigotAPIClient $client, - protected Resource $data + Resource $data ) { + parent::__construct($data->container); } + /** + * @deprecated The project extends the generated model now, so its getters can be used directly. + * @return Resource + */ public function getData(): Resource { - return $this->data; + return $this; } /** @@ -28,7 +33,7 @@ public function getData(): Resource */ public function getId(): int { - return intval($this->data->getId()); + return intval(parent::getId()); } /** @@ -36,19 +41,20 @@ public function getId(): int * * @return Category */ - public function getCategory(): Category + public function getCategoryType(): Category { - return Category::from($this->getData()->getCategory()->getId()); + return Category::from($this->getCategory()->getId()); } /** - * Get the author of the project. + * Fetch the author of the project from the API. * + * @return Author * @throws ApiException */ - public function getAuthor(): Author + public function fetchAuthor(): Author { - return $this->client->getAuthor($this->data->getAuthor()->getId()); + return $this->client->getAuthor($this->getAuthor()->getId()); } /** diff --git a/src/Client/Version.php b/src/Client/Version.php index 9e7a9f3..811fb07 100644 --- a/src/Client/Version.php +++ b/src/Client/Version.php @@ -5,19 +5,24 @@ use Aternos\SpigotApi\ApiException; use Aternos\SpigotApi\Model\ResourceUpdate; -class Version +class Version extends ResourceUpdate { public function __construct( protected SpigotAPIClient $client, - protected ResourceUpdate $data + ResourceUpdate $data ) { + parent::__construct($data->container); } + /** + * @deprecated The version extends the generated model now, so its getters can be used directly. + * @return ResourceUpdate + */ public function getData(): ResourceUpdate { - return $this->data; + return $this; } /** @@ -27,7 +32,7 @@ public function getData(): ResourceUpdate */ public function getId(): int { - return intval($this->data->getId()); + return intval(parent::getId()); } /** @@ -37,7 +42,7 @@ public function getId(): int */ public function getProjectId(): int { - return intval($this->getData()->getResourceId()); + return intval($this->getResourceId()); } /** @@ -50,4 +55,4 @@ public function getProject(): Project { return $this->client->getProject($this->getProjectId()); } -} \ No newline at end of file +} diff --git a/tests/Integration/Client/ClientTest.php b/tests/Integration/Client/ClientTest.php index fe8fedb..daa0b08 100644 --- a/tests/Integration/Client/ClientTest.php +++ b/tests/Integration/Client/ClientTest.php @@ -26,10 +26,10 @@ public function testListProjectsOrderedByDownloadCount(): void // collect the download counts of all projects from both pages $downloadCounts = []; foreach ($firstPage as $project) { - $downloadCounts[] = $project->getData()->getStats()->getDownloads(); + $downloadCounts[] = $project->getStats()->getDownloads(); } foreach ($secondPage as $project) { - $downloadCounts[] = $project->getData()->getStats()->getDownloads(); + $downloadCounts[] = $project->getStats()->getDownloads(); } $this->assertNotEmpty($downloadCounts); @@ -47,10 +47,10 @@ public function testGetProjectVersionsOrderedByPostDate(): void // collect the post dates of all versions from both pages $postDates = []; foreach ($firstPage as $version) { - $postDates[] = $version->getData()->getPostDate(); + $postDates[] = $version->getPostDate(); } foreach ($secondPage as $version) { - $postDates[] = $version->getData()->getPostDate(); + $postDates[] = $version->getPostDate(); } $this->assertNotEmpty($postDates); @@ -267,9 +267,9 @@ public function testGetProject(): void { $project = $this->apiClient->getProject(2); $this->assertNotNull($project); - $this->assertEquals("HubKick", $project->getData()->getTitle()); - $this->assertEquals("Send players to lobby on kick. /lobby / hub", $project->getData()->getTag()); - $this->assertEquals(1364368470, $project->getData()->getFirstRelease()); + $this->assertEquals("HubKick", $project->getTitle()); + $this->assertEquals("Send players to lobby on kick. /lobby / hub", $project->getTag()); + $this->assertEquals(1364368470, $project->getFirstRelease()); } /** @@ -297,9 +297,9 @@ public function testGetVersion(): void // PlaceholderAPI by HelpChat $version = $this->apiClient->getVersion(352711); $this->assertNotNull($version); - $this->assertEquals("2.10.9 back to normal", $version->getData()->getTitle()); - $this->assertEquals(352711, $version->getData()->getId()); - $this->assertEquals(6245, $version->getData()->getResourceId()); + $this->assertEquals("2.10.9 back to normal", $version->getTitle()); + $this->assertEquals(352711, $version->getId()); + $this->assertEquals(6245, $version->getResourceId()); } /** @@ -309,8 +309,7 @@ public function testGetAuthor(): void { $author = $this->apiClient->getAuthor(100356); $this->assertNotNull($author); - $this->assertNotNull($author->getData()); - $this->assertEquals("Luck", $author->getData()->getUsername()); + $this->assertEquals("Luck", $author->getUsername()); } /** @@ -320,9 +319,8 @@ public function testFindAuthor(): void { $author = $this->apiClient->findAuthor("Luck"); $this->assertNotNull($author); - $this->assertNotNull($author->getData()); - $this->assertEquals("Luck", $author->getData()->getUsername()); - $this->assertEquals(100356, $author->getData()->getId()); + $this->assertEquals("Luck", $author->getUsername()); + $this->assertEquals(100356, $author->getId()); } } \ No newline at end of file diff --git a/tests/Integration/Client/ProjectTest.php b/tests/Integration/Client/ProjectTest.php index 9698c74..8c6ce2f 100644 --- a/tests/Integration/Client/ProjectTest.php +++ b/tests/Integration/Client/ProjectTest.php @@ -21,33 +21,33 @@ public function setUp(): void $this->project = $this->apiClient->getProject(57242); } - public function testGetCategory(): void + public function testGetCategoryType(): void { - $resourceCategory = $this->project->getData()->getCategory(); + $resourceCategory = $this->project->getCategory(); $this->assertEquals(15, $resourceCategory->getId()); $this->assertEquals("Tools and Utilities", $resourceCategory->getTitle()); $this->assertEquals("", $resourceCategory->getDescription()); - $category = $this->project->getCategory(); + $category = $this->project->getCategoryType(); $this->assertEquals(Category::SPIGOT_TOOLS_AND_UTILITIES, $category); } /** * @throws ApiException */ - public function testGetAuthor(): void + public function testFetchAuthor(): void { // Luck - $author = $this->project->getAuthor(); + $author = $this->project->fetchAuthor(); $this->assertNotNull($author); - $this->assertValidAuthor($author->getData()); + $this->assertValidAuthor($author); - $this->assertEquals(100356, $author->getData()->getId()); - $this->assertEquals("Luck", $author->getData()->getUsername()); - $this->assertGreaterThan(1, $author->getData()->getResourceCount()); - $this->assertStringStartsWith("https://www.spigotmc.org/data/avatars", $author->getData()->getAvatar()); + $this->assertEquals(100356, $author->getId()); + $this->assertEquals("Luck", $author->getUsername()); + $this->assertGreaterThan(1, $author->getResourceCount()); + $this->assertStringStartsWith("https://www.spigotmc.org/data/avatars", $author->getAvatar()); // 1759349337 -> Wed Oct 01 2025 - $this->assertGreaterThanOrEqual(1759349337, $author->getData()->getLastActivity()); + $this->assertGreaterThanOrEqual(1759349337, $author->getLastActivity()); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 6a55b58..bd3a2df 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -59,39 +59,37 @@ protected function assertValidCategory(ResourceCategory $category): void protected function assertValidProject(Project $project): void { - $this->assertNotNull($project->getData()); - - $this->assertNotNull($project->getData()->getStats()); - $this->assertValidStats($project->getData()->getStats()); - - $this->assertNotNull($project->getData()->getAuthor()); - $this->assertValidResourceAuthor($project->getData()->getAuthor()); - - $this->assertNotNull($project->getData()->getId()); - $this->assertNotNull($project->getData()->getTitle()); - $this->assertNotNull($project->getData()->getTag()); - $this->assertNotNull($project->getData()->getCurrentVersion()); - // $project->getData()->getNativeMinecraftVersion() can be null - // $this->assertNotNull($project->getData()->getSupportedMinecraftVersions()) can be null or empty - $this->assertNotNull($project->getData()->getIconLink()); - $this->assertNotNull($project->getData()->getExternalDownloadUrl()); - $this->assertNotNull($project->getData()->getDescription()); - $this->assertNotNull($project->getData()->getFirstRelease()); - $this->assertNotNull($project->getData()->getLastUpdate()); - $this->assertNotNull($project->getData()->getSourceCodeUrl()); - $this->assertNotNull($project->getData()->getDonateUrl()); + $this->assertNotNull($project->getStats()); + $this->assertValidStats($project->getStats()); + + $this->assertNotNull($project->getAuthor()); + $this->assertValidResourceAuthor($project->getAuthor()); + + $this->assertNotNull($project->getId()); + $this->assertNotNull($project->getTitle()); + $this->assertNotNull($project->getTag()); + $this->assertNotNull($project->getCurrentVersion()); + // $project->getNativeMinecraftVersion() can be null + // $this->assertNotNull($project->getSupportedMinecraftVersions()) can be null or empty + $this->assertNotNull($project->getIconLink()); + $this->assertNotNull($project->getExternalDownloadUrl()); + $this->assertNotNull($project->getDescription()); + $this->assertNotNull($project->getFirstRelease()); + $this->assertNotNull($project->getLastUpdate()); + $this->assertNotNull($project->getSourceCodeUrl()); + $this->assertNotNull($project->getDonateUrl()); } protected function assertValidVersion(Version $version): void { $this->assertNotNull($version->getId()); $this->assertNotNull($version->getProjectId()); - $this->assertNotNull($version->getData()->getId()); - $this->assertNotNull($version->getData()->getResourceId()); - $this->assertNotNull($version->getData()->getDownloadCount()); - $this->assertNotNull($version->getData()->getTitle()); - $this->assertNotNull($version->getData()->getMessage()); - $this->assertNotNull($version->getData()->getPostDate()); + $this->assertNotNull($version->getId()); + $this->assertNotNull($version->getResourceId()); + $this->assertNotNull($version->getDownloadCount()); + $this->assertNotNull($version->getTitle()); + $this->assertNotNull($version->getMessage()); + $this->assertNotNull($version->getPostDate()); } protected function assertValidPaginatedList(PaginatedList $list): void diff --git a/tests/Unit/Client/AuthorTest.php b/tests/Unit/Client/AuthorTest.php index 251d67e..6ebd702 100644 --- a/tests/Unit/Client/AuthorTest.php +++ b/tests/Unit/Client/AuthorTest.php @@ -4,6 +4,7 @@ use Aternos\SpigotApi\ApiException; use Aternos\SpigotApi\Client\Author; +use Aternos\SpigotApi\Model\Author as AuthorModel; use Aternos\SpigotApi\Tests\TestCase; use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; @@ -12,9 +13,9 @@ class AuthorTest extends TestCase { - protected function getAuthorModel(): \Aternos\SpigotApi\Model\Author + protected function getAuthorModel(): AuthorModel { - return new \Aternos\SpigotApi\Model\Author([ + return new AuthorModel([ "id" => 100356, "username" => "Luck", "resource_count" => 4, @@ -24,6 +25,22 @@ protected function getAuthorModel(): \Aternos\SpigotApi\Model\Author ]); } + public function testExtendsModel(): void + { + $author = new Author($this->apiClient, $this->getAuthorModel()); + + $this->assertInstanceOf(AuthorModel::class, $author); + $this->assertSame($this->getAuthorModel()->getUsername(), $author->getUsername()); + $this->assertSame($this->getAuthorModel()->getId(), $author->getId()); + } + + public function testGetDataReturnsAuthor(): void + { + $author = new Author($this->apiClient, $this->getAuthorModel()); + + $this->assertSame($author, $author->getData()); + } + /** * @throws ApiException */ @@ -41,7 +58,7 @@ public function testGetProjects(): void foreach ($projects as $project) { $this->assertValidProject($project); - $this->assertEquals($author->getId(), $project->getData()->getAuthor()->getId()); + $this->assertEquals($author->getId(), $project->getAuthor()->getId()); } } diff --git a/tests/Unit/Client/ClientTest.php b/tests/Unit/Client/ClientTest.php index 227fbaa..ee92141 100644 --- a/tests/Unit/Client/ClientTest.php +++ b/tests/Unit/Client/ClientTest.php @@ -50,7 +50,7 @@ public function testGetProjectsInCategory(): void foreach ($projectList as $project) { $this->assertValidProject($project); - $this->assertEquals(Category::SPIGOT->value, $project->getData()->getCategory()->getId()); + $this->assertEquals(Category::SPIGOT->value, $project->getCategory()->getId()); } } @@ -67,7 +67,7 @@ public function testGetProject(): void $project = $this->apiClient->getProject(2); $this->assertNotNull($project); $this->assertValidProject($project); - $this->assertEquals("spark", $project->getData()->getTitle()); + $this->assertEquals("spark", $project->getTitle()); } /** @@ -83,9 +83,9 @@ public function testGetVersion(): void $version = $this->apiClient->getVersion(352711); $this->assertNotNull($version); $this->assertValidVersion($version); - $this->assertEquals("spark", $version->getData()->getTitle()); - $this->assertEquals(227294, $version->getData()->getId()); - $this->assertEquals(57242, $version->getData()->getResourceId()); + $this->assertEquals("spark", $version->getTitle()); + $this->assertEquals(227294, $version->getId()); + $this->assertEquals(57242, $version->getResourceId()); } /** @@ -116,8 +116,7 @@ public function testGetAuthor(): void $user = $this->apiClient->getAuthor(1); $this->assertNotNull($user); - $this->assertNotNull($user->getData()); - $this->assertEquals("Luck", $user->getData()->getUsername()); + $this->assertEquals("Luck", $user->getUsername()); } /** @@ -132,9 +131,8 @@ public function testFindAuthor(): void $user = $this->apiClient->findAuthor("Luck"); $this->assertNotNull($user); - $this->assertNotNull($user->getData()); - $this->assertEquals("Luck", $user->getData()->getUsername()); - $this->assertEquals(100356, $user->getData()->getId()); + $this->assertEquals("Luck", $user->getUsername()); + $this->assertEquals(100356, $user->getId()); } /** @@ -154,7 +152,7 @@ public function testGetAuthorProjects(): void foreach ($projectList as $project) { $this->assertValidProject($project); - $this->assertEquals(100356, $project->getData()->getAuthor()->getId()); + $this->assertEquals(100356, $project->getAuthor()->getId()); } } diff --git a/tests/Unit/Client/ProjectTest.php b/tests/Unit/Client/ProjectTest.php index 1c65f4c..19b1977 100644 --- a/tests/Unit/Client/ProjectTest.php +++ b/tests/Unit/Client/ProjectTest.php @@ -91,17 +91,46 @@ protected function getResourceModel(): Resource ]); } - public function testGetCategory(): void + public function testExtendsModel(): void { $project = new Project($this->apiClient, $this->getResourceModel()); - $this->assertSame(Category::SPIGOT_TOOLS_AND_UTILITIES, $project->getCategory()); + $this->assertInstanceOf(Resource::class, $project); + $this->assertSame(57242, $project->getId()); + $this->assertSame("spark", $project->getTitle()); + $this->assertSame("1.10.119", $project->getCurrentVersion()); + } + + public function testGetDataReturnsProject(): void + { + $project = new Project($this->apiClient, $this->getResourceModel()); + + $this->assertSame($project, $project->getData()); + } + + public function testModelGettersDoNotSendRequests(): void + { + // the mock handler has no responses, so every request would fail + $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create(new MockHandler())])); + $project = new Project($this->apiClient, $this->getResourceModel()); + + $this->assertInstanceOf(ResourceAuthor::class, $project->getAuthor()); + $this->assertSame("Luck", $project->getAuthor()->getUsername()); + $this->assertInstanceOf(ResourceCategory::class, $project->getCategory()); + $this->assertSame("Tools and Utilities", $project->getCategory()->getTitle()); + } + + public function testGetCategoryType(): void + { + $project = new Project($this->apiClient, $this->getResourceModel()); + + $this->assertSame(Category::SPIGOT_TOOLS_AND_UTILITIES, $project->getCategoryType()); } /** * @throws ApiException */ - public function testGetAuthor(): void + public function testFetchAuthor(): void { $handler = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getAuthor.json")), @@ -109,14 +138,14 @@ public function testGetAuthor(): void $this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)])); $project = new Project($this->apiClient, $this->getResourceModel()); - $author = $project->getAuthor(); + $author = $project->fetchAuthor(); $this->assertNotNull($author); - $this->assertEquals(100356, $author->getData()->getId()); - $this->assertEquals("Luck", $author->getData()->getUsername()); - $this->assertGreaterThan(1, $author->getData()->getResourceCount()); - $this->assertStringStartsWith("https://www.spigotmc.org/data/avatars", $author->getData()->getAvatar()); + $this->assertEquals(100356, $author->getId()); + $this->assertEquals("Luck", $author->getUsername()); + $this->assertGreaterThan(1, $author->getResourceCount()); + $this->assertStringStartsWith("https://www.spigotmc.org/data/avatars", $author->getAvatar()); // 1759349337 -> Wed Oct 01 2025 - $this->assertGreaterThanOrEqual(1759349337, $author->getData()->getLastActivity()); + $this->assertGreaterThanOrEqual(1759349337, $author->getLastActivity()); } diff --git a/tests/Unit/Client/VersionTest.php b/tests/Unit/Client/VersionTest.php index 0d02361..96f95ee 100644 --- a/tests/Unit/Client/VersionTest.php +++ b/tests/Unit/Client/VersionTest.php @@ -43,6 +43,22 @@ protected function getResourceUpdateModel(): ResourceUpdate ]); } + public function testExtendsModel(): void + { + $version = new Version($this->apiClient, $this->getResourceUpdateModel()); + + $this->assertInstanceOf(ResourceUpdate::class, $version); + $this->assertSame($this->getResourceUpdateModel()->getTitle(), $version->getTitle()); + $this->assertSame($this->getResourceUpdateModel()->getId(), $version->getId()); + } + + public function testGetDataReturnsVersion(): void + { + $version = new Version($this->apiClient, $this->getResourceUpdateModel()); + + $this->assertSame($version, $version->getData()); + } + public function testGetProjectId(): void { $version = new Version($this->apiClient, $this->getResourceUpdateModel()); @@ -62,8 +78,8 @@ public function testGetProject(): void $project = $version->getProject(); $this->assertNotNull($project); - $this->assertEquals(57242, $project->getData()->getId()); - $this->assertEquals("spark", $project->getData()->getTitle()); + $this->assertEquals(57242, $project->getId()); + $this->assertEquals("spark", $project->getTitle()); } } \ No newline at end of file From ff4944b38d5ae475b97cce1e9ca4a7fcac5648e7 Mon Sep 17 00:00:00 2001 From: Paul Vogel Date: Tue, 20 Oct 2026 12:36:01 +0200 Subject: [PATCH 2/2] remove deprecated getData() from the wrappers --- src/Client/Author.php | 9 --------- src/Client/Project.php | 13 +++---------- src/Client/Version.php | 9 --------- tests/Unit/Client/AuthorTest.php | 7 ------- tests/Unit/Client/ProjectTest.php | 7 ------- tests/Unit/Client/VersionTest.php | 7 ------- 6 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/Client/Author.php b/src/Client/Author.php index 8aab0ce..3e4617c 100644 --- a/src/Client/Author.php +++ b/src/Client/Author.php @@ -17,15 +17,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The author extends the generated model now, so its getters can be used directly. - * @return AuthorModel - */ - public function getData(): AuthorModel - { - return $this; - } - /** * Get the ID of the author. * diff --git a/src/Client/Project.php b/src/Client/Project.php index 6531107..0eecaa7 100644 --- a/src/Client/Project.php +++ b/src/Client/Project.php @@ -17,15 +17,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The project extends the generated model now, so its getters can be used directly. - * @return Resource - */ - public function getData(): Resource - { - return $this; - } - /** * Get the ID of the project. * @@ -47,7 +38,9 @@ public function getCategoryType(): Category } /** - * Fetch the author of the project from the API. + * Fetch the author of this project from the API. + * + * This sends a request to the SpigotMC API every time it is called. * * @return Author * @throws ApiException diff --git a/src/Client/Version.php b/src/Client/Version.php index 8d6b0a1..a74f941 100644 --- a/src/Client/Version.php +++ b/src/Client/Version.php @@ -16,15 +16,6 @@ public function __construct( parent::__construct($data->container); } - /** - * @deprecated The version extends the generated model now, so its getters can be used directly. - * @return ResourceUpdate - */ - public function getData(): ResourceUpdate - { - return $this; - } - /** * Get the ID of the version. * diff --git a/tests/Unit/Client/AuthorTest.php b/tests/Unit/Client/AuthorTest.php index 18a65a7..8b40b26 100644 --- a/tests/Unit/Client/AuthorTest.php +++ b/tests/Unit/Client/AuthorTest.php @@ -34,13 +34,6 @@ public function testExtendsModel(): void $this->assertSame($this->getAuthorModel()->getId(), $author->getId()); } - public function testGetDataReturnsAuthor(): void - { - $author = new Author($this->apiClient, $this->getAuthorModel()); - - $this->assertSame($author, $author->getData()); - } - /** * @throws ApiException */ diff --git a/tests/Unit/Client/ProjectTest.php b/tests/Unit/Client/ProjectTest.php index e21ab6b..ad066cf 100644 --- a/tests/Unit/Client/ProjectTest.php +++ b/tests/Unit/Client/ProjectTest.php @@ -101,13 +101,6 @@ public function testExtendsModel(): void $this->assertSame("1.10.119", $project->getCurrentVersion()); } - public function testGetDataReturnsProject(): void - { - $project = new Project($this->apiClient, $this->getResourceModel()); - - $this->assertSame($project, $project->getData()); - } - public function testModelGettersDoNotSendRequests(): void { // the mock handler has no responses, so every request would fail diff --git a/tests/Unit/Client/VersionTest.php b/tests/Unit/Client/VersionTest.php index b0e57ea..9f34081 100644 --- a/tests/Unit/Client/VersionTest.php +++ b/tests/Unit/Client/VersionTest.php @@ -52,13 +52,6 @@ public function testExtendsModel(): void $this->assertSame($this->getResourceUpdateModel()->getId(), $version->getId()); } - public function testGetDataReturnsVersion(): void - { - $version = new Version($this->apiClient, $this->getResourceUpdateModel()); - - $this->assertSame($version, $version->getData()); - } - public function testGetProjectId(): void { $version = new Version($this->apiClient, $this->getResourceUpdateModel());