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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ $version = $spigotClient->getVersion(352711);
// get the ID of the project this version belongs to
$projectId = $version->getProjectId();

// get the project as a Project wrapper
$project = $version->getProject();
// fetch the project from the API as a Project wrapper (sends a request)
$project = $version->fetchProject();
```

## Updating the generated code
Expand Down
22 changes: 19 additions & 3 deletions src/Client/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,29 @@ public function getProjectId(): int
}

/**
* Get the project this version belongs to.
* Fetch the project this version belongs to from the API.
*
* This sends a request to the SpigotMC API every time it is called. The result is not cached.
*
* @return Project
* @throws ApiException
*/
public function getProject(): Project
public function fetchProject(): Project
{
return $this->client->getProject($this->getProjectId());
}
}

/**
* Fetch the project this version belongs to from the API.
*
* This sends a request to the SpigotMC API every time it is called. The result is not cached.
*
* @deprecated Use {@see fetchProject()} instead. Methods that send a request to the API are prefixed with "fetch".
* @return Project
* @throws ApiException
*/
public function getProject(): Project
{
return $this->fetchProject();
}
}
2 changes: 1 addition & 1 deletion tests/Integration/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function testGetVersionsFromProject(): void
foreach ($versions as $version) {
$this->assertNotNull($version);
$this->assertInstanceOf(Version::class, $version);
$this->assertEquals($project, $version->getProject());
$this->assertEquals($project, $version->fetchProject());
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Client/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function testGetProjectId(): void
/**
* @throws ApiException
*/
public function testGetProject(): void
public function testFetchProject(): void
{
$project = $this->apiClient->getProject(6245);
$this->assertEquals($project, $this->version->getProject());
$this->assertEquals($project, $this->version->fetchProject());
}

}
20 changes: 18 additions & 2 deletions tests/Unit/Client/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,34 @@ public function testGetProjectId(): void
/**
* @throws ApiException
*/
public function testGetProject(): void
public function testFetchProject(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResource.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$version = new Version($this->apiClient, $this->getResourceUpdateModel());

$project = $version->getProject();
$project = $version->fetchProject();
$this->assertNotNull($project);
$this->assertEquals(57242, $project->getData()->getId());
$this->assertEquals("spark", $project->getData()->getTitle());
}

/**
* @throws ApiException
*/
public function testDeprecatedGetProjectFetchesProject(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResource.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$version = new Version($this->apiClient, $this->getResourceUpdateModel());

$project = $version->getProject();
$this->assertEquals(57242, $project->getId());
$this->assertSame(0, $handler->count());
}

}
Loading