Skip to content

Commit

Permalink
Added venue lookup endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nkl-kst committed Jun 28, 2024
1 parent 5880d5b commit ecfcef1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Client/Endpoint/LookupEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use NklKst\TheSportsDb\Entity\Player\Player;
use NklKst\TheSportsDb\Entity\Table\Table;
use NklKst\TheSportsDb\Entity\Team;
use NklKst\TheSportsDb\Entity\Venue;
use NklKst\TheSportsDb\Filter\LookupFilter;

/**
Expand All @@ -41,6 +42,7 @@ class LookupEndpoint extends AbstractEndpoint
private const ENDPOINT_TEAM = 'lookupteam.php';
private const ENDPOINT_TELEVISION = 'lookuptv.php';
private const ENDPOINT_TIMELINE = 'lookuptimeline.php';
private const ENDPOINT_VENUE = 'lookupvenue.php';

/**
* Get player contracts.
Expand Down Expand Up @@ -300,4 +302,19 @@ public function timeline(int $eventID): array

return $this->serializer->serializeTimeline($this->request());
}

/**
* Get venue by ID.
*
* @throws Exception
*/
public function venue(int $venueID): ?Venue
{
$this
->setFilter((new LookupFilter())->setID($venueID))
->requestBuilder->setEndpoint(self::ENDPOINT_VENUE)
;

return $this->getSingleEntity($this->serializer->serializeVenues($this->request()));
}
}
2 changes: 1 addition & 1 deletion src/Serializer/VenueSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ protected function getEntityClass(): string

protected function getValidJsonRootNames(): array
{
return ['venues'];
return ['honours', 'venues'];
}
}
16 changes: 16 additions & 0 deletions test/integration/LookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use NklKst\TheSportsDb\Entity\Table\Standing;
use NklKst\TheSportsDb\Entity\Table\Table;
use NklKst\TheSportsDb\Entity\Team;
use NklKst\TheSportsDb\Entity\Venue;
use NklKst\TheSportsDb\Util\TestUtils;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -81,6 +82,21 @@ public function testPlayer(): void
TestUtils::assertThatAllPropertiesAreInitialized($player);
}

/**
* Venue details by id (https://www.thesportsdb.com/api/v1/json/3/lookupvenue.php?id=16163).
*
* @throws Exception
*/
public function testVenue(): void
{
$venue = $this->client->lookup()->venue(16163);

$this->assertInstanceOf(Venue::class, $venue);
$this->assertSame('Wembley Stadium', $venue->strVenue);

TestUtils::assertThatAllPropertiesAreInitialized($venue);
}

/**
* Event details by id (https://www.thesportsdb.com/api/v1/json/{PATREON_KEY}/lookupevent.php?id=441613).
*
Expand Down
35 changes: 35 additions & 0 deletions test/unit/Client/Endpoint/LookupEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use NklKst\TheSportsDb\Entity\Player\Player;
use NklKst\TheSportsDb\Entity\Table\Table;
use NklKst\TheSportsDb\Entity\Team;
use NklKst\TheSportsDb\Entity\Venue;
use NklKst\TheSportsDb\Filter\LookupFilter;
use NklKst\TheSportsDb\Request\RequestBuilder;
use NklKst\TheSportsDb\Serializer\Serializer;
Expand Down Expand Up @@ -539,4 +540,38 @@ public function testTimelineInstances(): void
$this->assertNotEmpty($timeline);
$this->assertContainsOnlyInstancesOf(Timeline::class, $timeline);
}

/**
* @throws Exception
*/
public function testVenueFilterVenue(): void
{
$this->endpoint->venue(1);

$this->assertEquals(
(new LookupFilter())->setID(1),
TestUtils::getHiddenProperty($this->endpoint, 'filter'))
;
}

/**
* @throws Exception
*/
public function testVenueEndpoint(): void
{
TestUtils::expectEndpoint($this->requestBuilderMock, 'lookupvenue.php');
$this->endpoint->venue(1);
}

/**
* @throws Exception
*/
public function testVenueInstance(): void
{
$this->serializerStub->method('serializeVenues')->willReturn([new Venue()]);

$venue = $this->endpoint->venue(1);

$this->assertInstanceOf(Venue::class, $venue);
}
}

0 comments on commit ecfcef1

Please sign in to comment.