Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ $hangarClient = new HangarAPIClient(
$hangarClient->setHttpClient(new Client(["timeout" => 10]));
```

## Result Lists
Most methods return a paginated result list which contains a list of results on the current page and methods to
navigate to the next and previous page. The result list implements `Iterator`, `ArrayAccess` and `Countable` so
you can use it like an array. It also has a `getResults()` method which returns the underlying array of results.
## Paginated Lists
Most methods return a paginated list (`Aternos\HangarApi\Client\List\PaginatedList`) which contains the results
on the current page and methods to navigate to the next and previous page. The list implements `Iterator`,
`ArrayAccess` and `Countable` so you can use it like an array. It also has a `getResults()` method which returns the underlying array of results.
```php
$projects = $hangarClient->getProjects();

Expand Down
4 changes: 2 additions & 2 deletions src/Client/List/CompactProjectList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of compact projects
* @extends ResultList<CompactProject>
* @extends PaginatedList<CompactProject>
*/
abstract class CompactProjectList extends ResultList
abstract class CompactProjectList extends PaginatedList
{
public function __construct(
protected HangarAPIClient $client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Iterator;

/**
* Class ResultList
* Class PaginatedList
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of results
* @template T
*/
abstract class ResultList implements Iterator, ArrayAccess, Countable
abstract class PaginatedList implements Iterator, ArrayAccess, Countable
{
protected int $iterator = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/Client/List/ProjectList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of projects
* @extends ResultList<Project>
* @extends PaginatedList<Project>
*/
class ProjectList extends ResultList
class ProjectList extends PaginatedList
{
public function __construct(
protected HangarAPIClient $client,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/List/ProjectMemberList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of project members
* @extends ResultList<ProjectMember>
* @extends PaginatedList<ProjectMember>
*/
class ProjectMemberList extends ResultList
class ProjectMemberList extends PaginatedList
{
public function __construct(
protected HangarAPIClient $client,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/List/ProjectVersionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of versions
* @extends ResultList<Version>
* @extends PaginatedList<Version>
*/
class ProjectVersionList extends ResultList
class ProjectVersionList extends PaginatedList
{
public function __construct(
protected HangarAPIClient $client,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/List/UserList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*
* @package Aternos\HangarApi\Client\List
* @description A paginated list of users
* @extends ResultList<User>
* @extends PaginatedList<User>
*/
class UserList extends ResultList
class UserList extends PaginatedList
{
public function __construct(
protected HangarAPIClient $client,
Expand Down
62 changes: 31 additions & 31 deletions tests/Integration/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Aternos\HangarApi\ApiException;
use Aternos\HangarApi\Client\HangarAPIClient;
use Aternos\HangarApi\Client\List\ResultList;
use Aternos\HangarApi\Client\List\PaginatedList;
use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSearchOptions;
use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSortField;
use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSortOrder;
Expand Down Expand Up @@ -97,10 +97,10 @@ protected function assertValidCompactProject($project): void
$this->assertNotNull($project->getVisibility());
}

protected function assertValidResultList($list): void
protected function assertValidPaginatedList($list): void
{
$this->assertNotNull($list);
$this->assertInstanceOf(ResultList::class, $list);
$this->assertInstanceOf(PaginatedList::class, $list);
$this->assertNotEmpty($list);
$this->assertNotNull($list->getResults());
$this->assertNotEmpty($list->getResults());
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testGetProjects(): void

$firstProjectOfPages = [];
for ($i = 0; $i < 3; $i++) {
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);
$firstProjectOfPages[$i] = $projectList[0];

foreach ($projectList as $project) {
Expand All @@ -154,7 +154,7 @@ public function testGetProjects(): void
$this->assertTrue($projectList->hasPreviousPage());
$projectList = $projectList->getPreviousPage();

$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);
$this->assertTrue($this->isSameProject($firstProjectOfPages[$i], $projectList[0]));

foreach ($projectList as $project) {
Expand All @@ -179,7 +179,7 @@ public function testGetProjectsInCategory(): void

$firstProjectOfPages = [];
for ($i = 0; $i < 3; $i++) {
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);
$firstProjectOfPages[$i] = $projectList[0];

foreach ($projectList as $project) {
Expand All @@ -195,7 +195,7 @@ public function testGetProjectsInCategory(): void
$this->assertTrue($projectList->hasPreviousPage());
$projectList = $projectList->getPreviousPage();

$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);
$this->assertTrue($this->isSameProject($firstProjectOfPages[$i], $projectList[0]));

foreach ($projectList as $project) {
Expand All @@ -217,7 +217,7 @@ public function testGetProjectsByOwner(): void
$options->setOwner("Aternos");
$options->setLimit(10);
$projectList = $this->apiClient->getProjects($options);
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);

foreach ($projectList as $project) {
$this->assertValidProject($project);
Expand All @@ -241,7 +241,7 @@ public function testGetRecentlyUpdatedProjects(): void
$options->setSortField(ProjectSortField::UPDATED);
$options->setSortOrder(ProjectSortOrder::DESC);
$projectList = $this->apiClient->getProjects($options);
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);

$lastUpdated = time();
foreach ($projectList as $project) {
Expand All @@ -263,7 +263,7 @@ public function testGetNotRecentlyUpdatedProjects(): void
$options->setSortField(ProjectSortField::UPDATED);
$options->setSortOrder(ProjectSortOrder::ASC);
$projectList = $this->apiClient->getProjects($options);
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);

$lastUpdated = 0;
foreach ($projectList as $project) {
Expand All @@ -285,7 +285,7 @@ public function testGetProjectsSortedBySlug(): void
$options->setSortField(ProjectSortField::SLUG);
$options->setSortOrder(ProjectSortOrder::ASC);
$projectList = $this->apiClient->getProjects($options);
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);

$lastSlug = null;
foreach ($projectList as $project) {
Expand Down Expand Up @@ -325,7 +325,7 @@ public function testProjectSortIsSupported(ProjectSortField $sortField, ProjectS
$options->setSortField($sortField);
$options->setSortOrder($sortOrder);
$projectList = $this->apiClient->getProjects($options);
$this->assertValidResultList($projectList);
$this->assertValidPaginatedList($projectList);
}

/**
Expand Down Expand Up @@ -361,7 +361,7 @@ public function testGetProjectMembers(): void
$this->assertEquals("Aternos", $project->getNamespace()->getOwner());

$members = $project->fetchMembers();
$this->assertValidResultList($members);
$this->assertValidPaginatedList($members);
$this->assertNotEmpty(array_filter($members->getResults(), function ($member) {
return $member->getUser() === "Aternos";
}));
Expand All @@ -379,14 +379,14 @@ public function testGetProjectWatchers(): void
$this->assertEquals("Aternos", $project->getNamespace()->getOwner());

$watchers = $project->fetchWatchers();
$this->assertValidResultList($watchers);
$this->assertValidPaginatedList($watchers);
$this->assertNotEmpty(array_filter($watchers->getResults(), function ($watcher) {
return $watcher->getName() === "Julian";
}));

foreach ($watchers as $watcher) {
$projects = $watcher->fetchWatchedProjects();
$this->assertValidResultList($projects);
$this->assertValidPaginatedList($projects);

if ($projects->hasNextPage()) {
// let's ignore people watching hundreds of projects to not spam the api
Expand Down Expand Up @@ -443,7 +443,7 @@ public function testGetDailyProjectVersionStats(): void
$this->assertValidProject($project);

$versions = $project->fetchVersions();
$this->assertValidResultList($versions);
$this->assertValidPaginatedList($versions);
foreach ($versions as $version) {
foreach ($version->getStats()->getPlatformDownloads() as $downloads) {
if ($downloads > 0) {
Expand Down Expand Up @@ -474,7 +474,7 @@ public function testGetUsers(): void

$firstUserOfPage = [];
for ($i = 0; $i < 3; $i++) {
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$firstUserOfPage[$i] = $users[0];

foreach ($users as $user) {
Expand All @@ -490,7 +490,7 @@ public function testGetUsers(): void
$this->assertTrue($users->hasPreviousPage());
$users = $users->getPreviousPage();

$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName());

foreach ($users as $user) {
Expand Down Expand Up @@ -524,7 +524,7 @@ public function testGetProjectsWatchedByUser(): void
$this->assertEquals("Julian", $user->getName());

$watched = $user->fetchWatchedProjects();
$this->assertValidResultList($watched);
$this->assertValidPaginatedList($watched);

foreach ($watched as $project) {
$this->assertValidCompactProject($project);
Expand All @@ -542,7 +542,7 @@ public function testGetProjectsStarredByUser(): void
$this->assertEquals("Julian", $user->getName());

$starred = $user->fetchStarredProjects();
$this->assertValidResultList($starred);
$this->assertValidPaginatedList($starred);

foreach ($starred as $project) {
$this->assertValidCompactProject($project);
Expand All @@ -558,7 +558,7 @@ public function testGetProjectsStarredByUserSortedByStarsKeepsSortOnNextPage():
$starred = $this->apiClient->getProjectsStarredByUser("kennytv", ProjectSortField::STARS, ProjectSortOrder::DESC, 3);
$stars = [];
for ($i = 0; $i < 2; $i++) {
$this->assertValidResultList($starred);
$this->assertValidPaginatedList($starred);
foreach ($starred as $project) {
$this->assertValidCompactProject($project);
$stars[] = $project->getStats()->getStars();
Expand All @@ -583,7 +583,7 @@ public function testProjectsStarredByUserSortIsSupported(ProjectSortField $sortF
}

$starred = $this->apiClient->getProjectsStarredByUser("kennytv", $sortField, $sortOrder, 1);
$this->assertValidResultList($starred);
$this->assertValidPaginatedList($starred);
}

/**
Expand All @@ -598,7 +598,7 @@ public function testProjectsWatchedByUserSortIsSupported(ProjectSortField $sortF
}

$watched = $this->apiClient->getProjectsWatchedByUser("kennytv", $sortField, $sortOrder, 1);
$this->assertValidResultList($watched);
$this->assertValidPaginatedList($watched);
}

/**
Expand All @@ -612,7 +612,7 @@ public function testGetProjectsOfUser(): void
$this->assertEquals("Aternos", $user->getName());

$projects = $user->fetchProjects();
$this->assertValidResultList($projects);
$this->assertValidPaginatedList($projects);

foreach ($projects as $project) {
$this->assertValidProject($project);
Expand All @@ -633,7 +633,7 @@ public function testGetStaff(): void

$firstUserOfPage = [];
for ($i = 0; $i < 3; $i++) {
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$firstUserOfPage[$i] = $users[0];

foreach ($users as $user) {
Expand All @@ -649,7 +649,7 @@ public function testGetStaff(): void
$this->assertTrue($users->hasPreviousPage());
$users = $users->getPreviousPage();

$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName());

foreach ($users as $user) {
Expand All @@ -672,7 +672,7 @@ public function testGetAuthors(): void

$firstUserOfPage = [];
for ($i = 0; $i < 3; $i++) {
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$firstUserOfPage[$i] = $users[0];

foreach ($users as $user) {
Expand All @@ -688,7 +688,7 @@ public function testGetAuthors(): void
$this->assertTrue($users->hasPreviousPage());
$users = $users->getPreviousPage();

$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
$this->assertEquals($firstUserOfPage[$i]->getName(), $users[0]->getName());

foreach ($users as $user) {
Expand Down Expand Up @@ -721,7 +721,7 @@ public static function staffSortProvider(): array
public function testStaffSortIsSupported(StaffSortField $sortField): void
{
$users = $this->apiClient->getStaff(sort: $sortField, limit: 1);
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
}

/**
Expand All @@ -745,7 +745,7 @@ public static function authorSortProvider(): array
public function testAuthorSortIsSupported(AuthorSortField $sortField): void
{
$users = $this->apiClient->getAuthors(sort: $sortField, limit: 1);
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
}

/**
Expand All @@ -757,7 +757,7 @@ public function testGetAuthorsSortedByNameKeepsSortOnNextPage(): void
$users = $this->apiClient->getAuthors(sort: AuthorSortField::NAME, limit: 5);
$names = [];
for ($i = 0; $i < 2; $i++) {
$this->assertValidResultList($users);
$this->assertValidPaginatedList($users);
foreach ($users as $user) {
$names[] = $user->getName();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Client/ClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function createClient(
}

/**
* Create an empty paginated result model, e.g. to create a result list without sending a request
* Create an empty paginated result model, e.g. to create a paginated list without sending a request
* @template T
* @param class-string<T> $class generated model class, e.g. PaginatedResultUser
* @param int $offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace Aternos\HangarApi\Tests\Unit\Client\List;

use Aternos\HangarApi\ApiException;
use Aternos\HangarApi\Client\List\ResultList;
use Aternos\HangarApi\Client\List\PaginatedList;
use Aternos\HangarApi\Client\Options\ProjectSearch\ProjectSearchOptions;
use Aternos\HangarApi\Client\Project;
use Aternos\HangarApi\Tests\Unit\Client\ClientTestCase;
use GuzzleHttp\Psr7\Response;

/**
* Tests the behavior that all lists share through {@see ResultList} using a project list
* Tests the behavior that all lists share through {@see PaginatedList} using a project list
*/
class ResultListTest extends ClientTestCase
class PaginatedListTest extends ClientTestCase
{
/**
* Response with the projects from the getProjects fixture and the given pagination
Expand Down
Loading