Skip to content

Commit

Permalink
feat: added rival resource
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 22, 2024
1 parent ad287ba commit d86ba3e
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 189 deletions.
15 changes: 3 additions & 12 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,22 +633,17 @@ $response = $api->referees()->getAllBySearchQuery('name');
### Rivals

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

#### `getAll`

```php
getAll(int $page = 1, int $perPage = 25, string $order = 'asc'): RivalCollection
getAll(): RivalCollection
```

Get all rivals:

```php
$rivals = $sportMonksFootball->rivals()->getAll();

foreach ($rivals->getData() as $rival) {
echo $rival->getRivalId();
}
$response = $api->rivals()->getAll();
```

#### `getAllByTeamId`
Expand All @@ -660,11 +655,7 @@ getAllByTeamId(int $teamId): RivalCollection
Get all rivals by team id:

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

foreach ($rivals->getData() as $rival) {
echo $rival->getRivalId();
}
$response = $api->rivals()->getAllByTeamId(1);
```

### Rounds
Expand Down
68 changes: 0 additions & 68 deletions src/Endpoint/RivalEndpoint.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Resource;

use ProgrammatorDev\SportMonksFootball\Entity\Response\RivalCollection;
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait;
use Psr\Http\Client\ClientExceptionInterface;

class RivalResource extends Resource
{
use PaginationTrait;

/**
* @throws ClientExceptionInterface
*/
public function getAll(): RivalCollection
{
$data = $this->api->request(
method: 'GET',
path: '/v3/football/rivals'
);

return new RivalCollection($data);
}

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

return new RivalCollection($data);
}
}
12 changes: 6 additions & 6 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use ProgrammatorDev\Api\Event\PostRequestEvent;
use ProgrammatorDev\Api\Event\ResponseContentsEvent;
use ProgrammatorDev\SportMonksFootball\Entity\Response\Error;
use ProgrammatorDev\SportMonksFootball\Exception\ApiErrorException;
use ProgrammatorDev\SportMonksFootball\Exception\BadRequestException;
use ProgrammatorDev\SportMonksFootball\Exception\FilterNotApplicableException;
use ProgrammatorDev\SportMonksFootball\Exception\ForbiddenException;
Expand Down Expand Up @@ -42,6 +41,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\PreMatchOddResource;
use ProgrammatorDev\SportMonksFootball\Resource\RefereeResource;
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;

class SportMonksFootball extends Api
{
Expand Down Expand Up @@ -133,11 +133,11 @@ public function regions(): RegionResource
return new RegionResource($this);
}

// public function rivals(): RivalEndpoint
// {
// return new RivalEndpoint($this);
// }
//
public function rivals(): RivalResource
{
return new RivalResource($this);
}

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

namespace ProgrammatorDev\SportMonksFootball\Test\Integration;

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

class RivalResourceTest extends AbstractTest
{
use TestCollectionResponseTrait;

public static function provideCollectionResponseData(): \Generator
{
yield 'get all' => [
RivalCollection::class,
MockResponse::RIVAL_COLLECTION_DATA,
'rivals',
'getAll'
];
yield 'get all by team id' => [
RivalCollection::class,
MockResponse::RIVAL_COLLECTION_DATA,
'rivals',
'getAllByTeamId',
[1]
];
}
}
2 changes: 2 additions & 0 deletions tests/Integration/SportMonksFootballTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ProgrammatorDev\SportMonksFootball\Resource\PreMatchOddResource;
use ProgrammatorDev\SportMonksFootball\Resource\RefereeResource;
use ProgrammatorDev\SportMonksFootball\Resource\RegionResource;
use ProgrammatorDev\SportMonksFootball\Resource\RivalResource;
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest;

class SportMonksFootballTest extends AbstractTest
Expand All @@ -38,5 +39,6 @@ public function testMethods()
$this->assertInstanceOf(PreMatchOddResource::class, $this->api->preMatchOdds());
$this->assertInstanceOf(RefereeResource::class, $this->api->referees());
$this->assertInstanceOf(RegionResource::class, $this->api->regions());
$this->assertInstanceOf(RivalResource::class, $this->api->rivals());
}
}
61 changes: 0 additions & 61 deletions tests/RegionEndpointTest_.php

This file was deleted.

42 changes: 0 additions & 42 deletions tests/RivalEndpointTest_.php

This file was deleted.

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

namespace ProgrammatorDev\SportMonksFootball\Test\Unit;

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

class RivalTest extends AbstractTest
{
public function testMethods(): void
{
$entity = new Rival([
'id' => 1,
'sport_id' => 1,
'team_id' => 1,
'rival_id' => 1
], 'UTC');

$this->assertSame(1, $entity->getId());
$this->assertSame(1, $entity->getSportId());
$this->assertSame(1, $entity->getTeamId());
$this->assertSame(1, $entity->getRivalId());
}
}

0 comments on commit d86ba3e

Please sign in to comment.