Skip to content

Commit

Permalink
feat: added schedule resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent eeabb10 commit 1d9f340
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 161 deletions.
43 changes: 3 additions & 40 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ $response = $api->rounds()->getAllBySearchQuery('30');
### Schedules

- [Official documentation](https://docs.sportmonks.com/football/endpoints-and-entities/endpoints/schedules)
- Cache default max age: `1 hour`

#### `getAllBySeasonId`

Expand All @@ -724,19 +723,7 @@ getAllBySeasonId(int $seasonId): StageCollection
Get complete season schedule by season id:

```php
$schedule = $sportMonksFootball->schedules()->getAllBySeasonId(1);

foreach ($schedule->getData() as $stage) {
echo $stage->getName();

foreach ($stage->getRounds() as $round) {
echo $round->getName();

foreach ($round->getFixtures() as $fixture) {
echo $fixture->getName();
}
}
}
$response = $api->schedules()->getAllBySeasonId(1);
```

#### `getAllByTeamId`
Expand All @@ -748,19 +735,7 @@ getAllByTeamId(int $teamId): StageCollection
Get complete schedule for all active seasons by team id:

```php
$schedule = $sportMonksFootball->schedules()->getAllByTeamId(1);

foreach ($schedule->getData() as $stage) {
echo $stage->getName();

foreach ($stage->getRounds() as $round) {
echo $round->getName();

foreach ($round->getFixtures() as $fixture) {
echo $fixture->getName();
}
}
}
$response = $api->schedules()->getAllByTeamId(1);
```

#### `getAllBySeasonIdAndTeamId`
Expand All @@ -772,19 +747,7 @@ getAllBySeasonIdAndTeamId(int $seasonId, int $teamId): StageCollection
Get complete season schedule for one team by season id and team id:

```php
$schedule = $sportMonksFootball->schedules()->getAllBySeasonIdAndTeamId(1, 1);

foreach ($schedule->getData() as $stage) {
echo $stage->getName();

foreach ($stage->getRounds() as $round) {
echo $round->getName();

foreach ($round->getFixtures() as $fixture) {
echo $fixture->getName();
}
}
}
$response = $api->schedules()->getAllBySeasonIdAndTeamId(1, 1);
```

### Seasons
Expand Down
66 changes: 0 additions & 66 deletions src/Endpoint/ScheduleEndpoint.php

This file was deleted.

55 changes: 55 additions & 0 deletions src/Resource/ScheduleResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\StageCollection;
use Psr\Http\Client\ClientExceptionInterface;

class ScheduleResource extends Resource
{
/**
* @throws ClientExceptionInterface
*/
public function getAllBySeasonId(int $seasonId): StageCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/schedules/seasons/{seasonId}', [
'seasonId' => $seasonId
])
);

return new StageCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllByTeamId(int $teamId): StageCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/schedules/teams/{teamId}', [
'teamId' => $teamId
])
);

return new StageCollection($data);
}

/**
* @throws ClientExceptionInterface
*/
public function getAllBySeasonIdAndTeamId(int $seasonId, int $teamId): StageCollection
{
$data = $this->api->request(
method: 'GET',
path: $this->api->buildPath('/v3/football/schedules/seasons/{seasonId}/teams/{teamId}', [
'seasonId' => $seasonId,
'teamId' => $teamId
])
);

return new StageCollection($data);
}
}
11 changes: 6 additions & 5 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;
use ProgrammatorDev\SportMonksFootball\Resource\RoundResource;
use ProgrammatorDev\SportMonksFootball\Resource\ScheduleResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -144,11 +145,11 @@ public function rounds(): RoundResource
return new RoundResource($this);
}

// public function schedules(): ScheduleEndpoint
// {
// return new ScheduleEndpoint($this);
// }
//
public function schedules(): ScheduleResource
{
return new ScheduleResource($this);
}

// public function seasons(): SeasonEndpoint
// {
// return new SeasonEndpoint($this);
Expand Down
38 changes: 38 additions & 0 deletions tests/Integration/ScheduleResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

use ProgrammatorDev\SportMonksFootball\Entity\Response\StageCollection;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;
use ProgrammatorDev\SportMonksFootball\Test\MockResponse;
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait;

class ScheduleResourceTest extends AbstractTest
{
use TestCollectionResponseTrait;

public static function provideCollectionResponseData(): \Generator
{
yield 'get all by season id' => [
StageCollection::class,
MockResponse::STAGE_COLLECTION_DATA,
'schedules',
'getAllBySeasonId',
[1]
];
yield 'get all by team id' => [
StageCollection::class,
MockResponse::STAGE_COLLECTION_DATA,
'schedules',
'getAllByTeamId',
[1]
];
yield 'get all by season id and team id' => [
StageCollection::class,
MockResponse::STAGE_COLLECTION_DATA,
'schedules',
'getAllBySeasonIdAndTeamId',
[1, 1]
];
}
}
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;
use ProgrammatorDev\SportMonksFootball\Resource\RoundResource;
use ProgrammatorDev\SportMonksFootball\Resource\ScheduleResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand All @@ -42,5 +43,6 @@ public function testMethods()
$this->assertInstanceOf(RegionResource::class, $this->api->regions());
$this->assertInstanceOf(RivalResource::class, $this->api->rivals());
$this->assertInstanceOf(RoundResource::class, $this->api->rounds());
$this->assertInstanceOf(ScheduleResource::class, $this->api->schedules());
}
}
50 changes: 0 additions & 50 deletions tests/ScheduleEndpointTest_.php

This file was deleted.

42 changes: 42 additions & 0 deletions tests/Unit/StageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Test\Unit;

use ProgrammatorDev\SportMonksFootball\Entity\Stage;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class StageTest extends AbstractTest
{
public function testMethods(): void
{
$entity = new Stage([
'id' => 1,
'sport_id' => 1,
'league_id' => 1,
'season_id' => 1,
'type_id' => 1,
'name' => 'name',
'sort_order' => 1,
'finished' => true,
'is_current' => false,
'starting_at' => '2024-01-01 16:00:00',
'ending_at' => '2024-01-07 16:00:00',
'games_in_current_week' => false,
'tie_breaker_rule_id' => 1
], 'UTC');

$this->assertSame(1, $entity->getId());
$this->assertSame(1, $entity->getSportId());
$this->assertSame(1, $entity->getLeagueId());
$this->assertSame(1, $entity->getSeasonId());
$this->assertSame(1, $entity->getTypeId());
$this->assertSame('name', $entity->getName());
$this->assertSame(1, $entity->getSortOrder());
$this->assertSame(true, $entity->hasFinished());
$this->assertSame(false, $entity->isCurrent());
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getStartingAt());
$this->assertInstanceOf(\DateTimeImmutable::class, $entity->getEndingAt());
$this->assertSame(false, $entity->hasGamesInCurrentWeek());
$this->assertSame(1, $entity->getTieBreakerRuleId());
}
}

0 comments on commit 1d9f340

Please sign in to comment.