Skip to content

Commit

Permalink
Ability to get the game detalization using slug
Browse files Browse the repository at this point in the history
  • Loading branch information
dimuska139 committed Jun 1, 2022
1 parent 84cc5c4 commit dd32f81
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class Filter
*/
public function toArray(): array
{
return array_filter(get_object_vars($this), function($element){
return array_filter(get_object_vars($this), static function($element){
return !is_null($element);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/GamesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public function getStores(int $id, OrderingFilter $filter): Response
}

/**
* @param int $id
* @param int|string $idOrSlug
* @return Response
* @throws ApiException
*/
public function getGame(int $id): Response
public function getGame($idOrSlug): Response
{
return $this->get("/games/$id");
return $this->get("/games/$idOrSlug");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Resources/DevelopersResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function testGetDeveloper()
$cfg = new Config(getenv(ENV_API_KEY));
$client = new ApiClient($cfg);

$response = $client->developers()->getDeveloper(1);
$response = $client->developers()->getDeveloper(405);
$this->assertEquals(Status::HTTP_OK, $response->getResponse()->getStatusCode());
$this->assertEquals("D3 Publisher of America", $response->getData()['name']);
$this->assertEquals("Ubisoft", $response->getData()['name']);
}
}
18 changes: 14 additions & 4 deletions tests/unit/Resources/GamesResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,24 @@ public function testGetStores()
$this->assertNotCount(0, $response->getData()['results']);
}

public function testGetGame()
public function testGetGameById()
{
$cfg = new Config(getenv(ENV_API_KEY));
$client = new ApiClient($cfg);

$response = $client->games()->getGame(1);
$response = $client->games()->getGame(4286);
$this->assertEquals(Status::HTTP_OK, $response->getResponse()->getStatusCode());
$this->assertEquals("D/Generation HD", $response->getData()['name']);
$this->assertEquals("BioShock", $response->getData()['name']);
}

public function testGetGameBySlug()
{
$cfg = new Config(getenv(ENV_API_KEY));
$client = new ApiClient($cfg);

$response = $client->games()->getGame('bioshock');
$this->assertEquals(Status::HTTP_OK, $response->getResponse()->getStatusCode());
$this->assertEquals("BioShock", $response->getData()['name']);
}

public function testGetArchievements()
Expand Down Expand Up @@ -157,7 +167,7 @@ public function testGetTwitch()
$cfg = new Config(getenv(ENV_API_KEY));
$client = new ApiClient($cfg);

$response = $client->games()->getTwitchVideos(1);
$response = $client->games()->getTwitchVideos(10213);
$this->assertEquals(Status::HTTP_OK, $response->getResponse()->getStatusCode());
$this->assertNotNull($response->getData()['count']);
$this->assertNotCount(0, $response->getData()['results']);
Expand Down

0 comments on commit dd32f81

Please sign in to comment.