-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor pass to argument and added more testing
- Loading branch information
1 parent
661b129
commit d3019da
Showing
15 changed files
with
273 additions
and
15 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 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
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
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
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,41 @@ | ||
<?php | ||
|
||
namespace Fluent\Repository\Tests\Criteria; | ||
|
||
use CodeIgniter\Model; | ||
use Fluent\Repository\Contracts\CriterionInterface; | ||
|
||
class SampleCriteria implements CriterionInterface | ||
{ | ||
/** @var array $conditions */ | ||
protected $conditions; | ||
|
||
/** | ||
* Constructor FindWhare. | ||
* | ||
* @param array $conditions | ||
* @return void | ||
*/ | ||
public function __construct(array $conditions) | ||
{ | ||
$this->conditions = $conditions; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply(Model $entity) | ||
{ | ||
foreach ($this->conditions as $field => $value) | ||
{ | ||
if (is_array($value)) { | ||
list($field, $condition, $val) = $value; | ||
$entity = $entity->orWhere($field . $condition, $val); | ||
} else { | ||
$entity = $entity->where($field, $value); | ||
} | ||
|
||
return $entity; | ||
} | ||
} | ||
} |
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,133 @@ | ||
<?php | ||
|
||
namespace Fluent\Repository\Tests; | ||
|
||
use CodeIgniter\Config\Services; | ||
use CodeIgniter\I18n\Time; | ||
use CodeIgniter\Test\CIDatabaseTestCase; | ||
use CodeIgniter\Test\ControllerTester; | ||
use Fluent\Repository\Tests\Repository\NewsRepositoryScope; | ||
use Tests\Support\Database\Seeds\NewsSeeder; | ||
|
||
class NewsRepositoryRequestTest extends CIDatabaseTestCase | ||
{ | ||
protected $refresh = false; | ||
|
||
protected $seed = NewsSeeder::class; | ||
|
||
/** @var NewsRepositoryScope */ | ||
protected $repository; | ||
|
||
/** @var \CodeIgniter\HTTP\IncomingRequest */ | ||
protected $request; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
/** @var NewsRepositoryScope */ | ||
$this->repository = new NewsRepositoryScope(); | ||
|
||
$this->request = Services::request(); | ||
} | ||
|
||
public function testRepositoryMyCustomScope() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'id' => '1', | ||
] | ||
); | ||
|
||
$this->assertNotEmpty($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryMyCustomScopeIsNull() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'id' => '1000', | ||
] | ||
); | ||
|
||
$this->assertNull($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryScopeTitle() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'title' => 'A', | ||
] | ||
); | ||
|
||
$this->assertNotEmpty($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryScopeTitleIsNull() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'title' => 'Aaaaaa', | ||
] | ||
); | ||
|
||
$this->assertNull($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryScopeDescription() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'description' => 'A', | ||
] | ||
); | ||
|
||
$this->assertNotEmpty($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryScopeDescriptionIsNull() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'description' => 'Aaaaaa', | ||
] | ||
); | ||
|
||
$this->assertNull($this->repository->scope(Services::request())->first()); | ||
} | ||
|
||
public function testRepositoryScopeRequestOrderByAsc() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'orderBy' => 'title_asc', | ||
] | ||
); | ||
|
||
$this->assertNotEmpty($this->repository->scope(Services::request())->paginate()); | ||
} | ||
|
||
public function testRepositoryScopeRequestOrderByDesc() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'orderBy' => 'title_desc', | ||
] | ||
); | ||
|
||
$this->assertNotEmpty($this->repository->scope(Services::request())->paginate()); | ||
} | ||
|
||
public function testRepositoryScopeRequestBeginEnd() | ||
{ | ||
$this->request->setMethod('get') | ||
->setGlobal('get', [ | ||
'begin' => Time::now(), | ||
'end' => Time::now(), | ||
] | ||
); | ||
|
||
$this->assertNotNull($this->repository->scope(Services::request())->paginate()); | ||
} | ||
} |
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.