-
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.
feat: added select, include and select traits
- Loading branch information
1 parent
d15978f
commit ba224f0
Showing
14 changed files
with
308 additions
and
102 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,16 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Resource\Util; | ||
|
||
use function DeepCopy\deep_copy; | ||
|
||
trait FilterTrait | ||
{ | ||
public function withFilter(string $filter): static | ||
{ | ||
$clone = deep_copy($this, true); | ||
$clone->api->addQueryDefault('filters', $filter); | ||
|
||
return $clone; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Resource\Util; | ||
|
||
use function DeepCopy\deep_copy; | ||
|
||
trait IncludeTrait | ||
{ | ||
public function withInclude(string $include): static | ||
{ | ||
$clone = deep_copy($this, true); | ||
$clone->api->addQueryDefault('include', $include); | ||
|
||
return $clone; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Resource\Util; | ||
|
||
use function DeepCopy\deep_copy; | ||
|
||
trait SelectTrait | ||
{ | ||
public function withSelect(string $select): static | ||
{ | ||
$clone = deep_copy($this, true); | ||
$clone->api->addQueryDefault('select', $select); | ||
|
||
return $clone; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\Api\Builder\CacheBuilder; | ||
use ProgrammatorDev\SportMonksFootball\Resource\Resource; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
class CacheTraitTest extends AbstractTest | ||
{ | ||
private Resource $resource; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$pool = $this->createMock(CacheItemPoolInterface::class); | ||
$cacheBuilder = new CacheBuilder($pool); | ||
|
||
$this->api->setCacheBuilder($cacheBuilder); | ||
|
||
$this->resource = new class($this->api) extends Resource { | ||
public function getCacheTtl(): ?int | ||
{ | ||
return $this->api->getCacheBuilder()?->getTtl(); | ||
} | ||
}; | ||
} | ||
|
||
public function testMethods(): void | ||
{ | ||
$this->assertSame(600, $this->resource->withCacheTtl(600)->getCacheTtl()); | ||
$this->assertSame(60, $this->resource->getCacheTtl()); // back to default value | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Resource\Resource; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
|
||
class FilterTraitTest extends AbstractTest | ||
{ | ||
private Resource $resource; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->resource = new class($this->api) extends Resource { | ||
public function getFilter(): ?string | ||
{ | ||
return $this->api->getQueryDefault('filters'); | ||
} | ||
}; | ||
} | ||
|
||
public function testMethods(): void | ||
{ | ||
$this->assertSame('eventTypes:18,17', $this->resource->withFilter('eventTypes:18,17')->getFilter()); | ||
$this->assertSame(null, $this->resource->getFilter()); // back to default value | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Resource\Resource; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
|
||
class IncludeTraitTest extends AbstractTest | ||
{ | ||
private Resource $resource; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->resource = new class($this->api) extends Resource { | ||
public function getInclude(): ?string | ||
{ | ||
return $this->api->getQueryDefault('include'); | ||
} | ||
}; | ||
} | ||
|
||
public function testMethods(): void | ||
{ | ||
$this->assertSame('fixtures;teams', $this->resource->withInclude('fixtures;teams')->getInclude()); | ||
$this->assertSame(null, $this->resource->getInclude()); // back to default value | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Resource\Resource; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
|
||
class LanguageTraitTest extends AbstractTest | ||
{ | ||
private Resource $resource; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->resource = new class($this->api) extends Resource { | ||
public function getLanguage(): string | ||
{ | ||
return $this->api->getQueryDefault('locale'); | ||
} | ||
}; | ||
} | ||
|
||
public function testMethods(): void | ||
{ | ||
$this->assertSame('pt', $this->resource->withLanguage('pt')->getLanguage()); | ||
$this->assertSame('en', $this->resource->getLanguage()); // back to default value | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
namespace ProgrammatorDev\SportMonksFootball\Test\Integration; | ||
|
||
use ProgrammatorDev\SportMonksFootball\Resource\Resource; | ||
use ProgrammatorDev\SportMonksFootball\Resource\Util\PaginationTrait; | ||
use ProgrammatorDev\SportMonksFootball\Test\AbstractTest; | ||
|
||
class PaginationTraitTest extends AbstractTest | ||
{ | ||
private Resource $resource; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->resource = new class($this->api) extends Resource { | ||
use PaginationTrait; | ||
|
||
public function getPage(): ?int | ||
{ | ||
return $this->api->getQueryDefault('page'); | ||
} | ||
|
||
public function getPerPage(): ?int | ||
{ | ||
return $this->api->getQueryDefault('per_page'); | ||
} | ||
|
||
public function getSortBy(): ?string | ||
{ | ||
return $this->api->getQueryDefault('sortBy'); | ||
} | ||
|
||
public function getOrder(): ?string | ||
{ | ||
return $this->api->getQueryDefault('order'); | ||
} | ||
}; | ||
} | ||
|
||
public function testMethods(): void | ||
{ | ||
$this->assertSame(1, $this->resource->withPage(1)->getPage()); | ||
$this->assertSame(null, $this->resource->getPage()); | ||
|
||
$this->assertSame(25, $this->resource->withPerPage(25)->getPerPage()); | ||
$this->assertSame(null, $this->resource->getPerPage()); | ||
|
||
$this->assertSame('name', $this->resource->withSortBy('name')->getSortBy()); | ||
$this->assertSame(null, $this->resource->getSortBy()); | ||
|
||
$this->assertSame('asc', $this->resource->withOrder('asc')->getOrder()); | ||
$this->assertSame(null, $this->resource->getOrder()); | ||
|
||
$this->assertSame(1, $this->resource->withPagination(page: 1)->getPage()); | ||
$this->assertSame(25, $this->resource->withPagination(page: 1, perPage: 25)->getPerPage()); | ||
$this->assertSame('name', $this->resource->withPagination(page: 1, sortBy: 'name')->getSortBy()); | ||
$this->assertSame('asc', $this->resource->withPagination(page: 1, order: 'asc')->getOrder()); | ||
} | ||
} |
Oops, something went wrong.