From dd32f81d65d39eedbf2841187361a61080379b9e Mon Sep 17 00:00:00 2001 From: Dmitriy Sviridov Date: Thu, 2 Jun 2022 00:47:09 +0300 Subject: [PATCH] Ability to get the game detalization using slug --- src/Filters/Filter.php | 2 +- src/Resources/GamesResource.php | 6 +++--- .../unit/Resources/DevelopersResourceTest.php | 4 ++-- tests/unit/Resources/GamesResourceTest.php | 18 ++++++++++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Filters/Filter.php b/src/Filters/Filter.php index 096342d..888420d 100644 --- a/src/Filters/Filter.php +++ b/src/Filters/Filter.php @@ -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); }); } diff --git a/src/Resources/GamesResource.php b/src/Resources/GamesResource.php index 586173b..ada4e6d 100644 --- a/src/Resources/GamesResource.php +++ b/src/Resources/GamesResource.php @@ -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"); } /** diff --git a/tests/unit/Resources/DevelopersResourceTest.php b/tests/unit/Resources/DevelopersResourceTest.php index 90a33a1..f5ce770 100644 --- a/tests/unit/Resources/DevelopersResourceTest.php +++ b/tests/unit/Resources/DevelopersResourceTest.php @@ -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']); } } diff --git a/tests/unit/Resources/GamesResourceTest.php b/tests/unit/Resources/GamesResourceTest.php index a2d3f46..1a900a8 100644 --- a/tests/unit/Resources/GamesResourceTest.php +++ b/tests/unit/Resources/GamesResourceTest.php @@ -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() @@ -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']);