-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d9f340
commit 3b9ba11
Showing
8 changed files
with
191 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Resource; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Entity\Response\SeasonCollection; | ||
use ProgrammatorDev\SportMonksFootball\Entity\Response\SeasonItem; | ||
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait; | ||
use ProgrammatorDev\Validator\Exception\ValidationException; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
|
||
class SeasonResource extends Resource | ||
{ | ||
use PaginationTrait; | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAll(): SeasonCollection | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: '/v3/football/seasons' | ||
); | ||
|
||
return new SeasonCollection($data); | ||
} | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getById(int $id): SeasonItem | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/seasons/{id}', [ | ||
'id' => $id | ||
]) | ||
); | ||
|
||
return new SeasonItem($data); | ||
} | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAllByTeamId(int $teamId): SeasonCollection | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/seasons/teams/{teamId}', [ | ||
'teamId' => $teamId | ||
]) | ||
); | ||
|
||
return new SeasonCollection($data); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAllBySearchQuery(string $query): SeasonCollection | ||
{ | ||
$this->validateQuery($query, 'query'); | ||
|
||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/seasons/search/{query}', [ | ||
'query' => $query | ||
]) | ||
); | ||
|
||
return new SeasonCollection($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Entity\Response\SeasonCollection; | ||
use ProgrammatorDev\SportMonksFootball\Entity\Response\SeasonItem; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
use ProgrammatorDev\SportMonksFootball\Test\MockResponse; | ||
use ProgrammatorDev\SportMonksFootball\Test\Util\TestCollectionResponseTrait; | ||
use ProgrammatorDev\SportMonksFootball\Test\Util\TestItemResponseTrait; | ||
use ProgrammatorDev\SportMonksFootball\Test\Util\TestValidationExceptionTrait; | ||
|
||
class SeasonResourceTest extends AbstractTest | ||
{ | ||
use TestItemResponseTrait; | ||
use TestCollectionResponseTrait; | ||
use TestValidationExceptionTrait; | ||
|
||
public static function provideItemResponseData(): \Generator | ||
{ | ||
yield 'get by id' => [ | ||
SeasonItem::class, | ||
MockResponse::SEASON_ITEM_DATA, | ||
'seasons', | ||
'getById', | ||
[1] | ||
]; | ||
} | ||
|
||
public static function provideCollectionResponseData(): \Generator | ||
{ | ||
yield 'get all' => [ | ||
SeasonCollection::class, | ||
MockResponse::SEASON_COLLECTION_DATA, | ||
'seasons', | ||
'getAll' | ||
]; | ||
yield 'get all by team id' => [ | ||
SeasonCollection::class, | ||
MockResponse::SEASON_COLLECTION_DATA, | ||
'seasons', | ||
'getAllByTeamId', | ||
[1] | ||
]; | ||
yield 'get all by search query' => [ | ||
SeasonCollection::class, | ||
MockResponse::SEASON_COLLECTION_DATA, | ||
'seasons', | ||
'getAllBySearchQuery', | ||
['test'] | ||
]; | ||
} | ||
|
||
public static function provideValidationExceptionData(): \Generator | ||
{ | ||
yield 'get all by search query, blank query' => [ | ||
'seasons', | ||
'getAllBySearchQuery', | ||
[''] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.