-
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
d86ba3e
commit eeabb10
Showing
8 changed files
with
189 additions
and
213 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\RoundCollection; | ||
use ProgrammatorDev\SportMonksFootball\Entity\Response\RoundItem; | ||
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait; | ||
use ProgrammatorDev\Validator\Exception\ValidationException; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
|
||
class RoundResource extends Resource | ||
{ | ||
use PaginationTrait; | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAll(): RoundCollection | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: '/v3/football/rounds' | ||
); | ||
|
||
return new RoundCollection($data); | ||
} | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getById(int $id): RoundItem | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/rounds/{id}', [ | ||
'id' => $id | ||
]) | ||
); | ||
|
||
return new RoundItem($data); | ||
} | ||
|
||
/** | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAllBySeasonId(int $seasonId): RoundCollection | ||
{ | ||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/rounds/seasons/{seasonId}', [ | ||
'seasonId' => $seasonId | ||
]) | ||
); | ||
|
||
return new RoundCollection($data); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getAllBySearchQuery(string $query): RoundCollection | ||
{ | ||
$this->validateQuery($query, 'query'); | ||
|
||
$data = $this->api->request( | ||
method: 'GET', | ||
path: $this->api->buildPath('/v3/football/rounds/search/{query}', [ | ||
'query' => $query | ||
]) | ||
); | ||
|
||
return new RoundCollection($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\RoundCollection; | ||
use ProgrammatorDev\SportMonksFootball\Entity\Response\RoundItem; | ||
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 RoundResourceTest extends AbstractTest | ||
{ | ||
use TestItemResponseTrait; | ||
use TestCollectionResponseTrait; | ||
use TestValidationExceptionTrait; | ||
|
||
public static function provideItemResponseData(): \Generator | ||
{ | ||
yield 'get by id' => [ | ||
RoundItem::class, | ||
MockResponse::ROUND_ITEM_DATA, | ||
'rounds', | ||
'getById', | ||
[1] | ||
]; | ||
} | ||
|
||
public static function provideCollectionResponseData(): \Generator | ||
{ | ||
yield 'get all' => [ | ||
RoundCollection::class, | ||
MockResponse::ROUND_COLLECTION_DATA, | ||
'rounds', | ||
'getAll' | ||
]; | ||
yield 'get all by season id' => [ | ||
RoundCollection::class, | ||
MockResponse::ROUND_COLLECTION_DATA, | ||
'rounds', | ||
'getAllBySeasonId', | ||
[1] | ||
]; | ||
yield 'get all by search query' => [ | ||
RoundCollection::class, | ||
MockResponse::ROUND_COLLECTION_DATA, | ||
'rounds', | ||
'getAllBySearchQuery', | ||
['test'] | ||
]; | ||
} | ||
|
||
public static function provideValidationExceptionData(): \Generator | ||
{ | ||
yield 'get all by search query, blank query' => [ | ||
'rounds', | ||
'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.