Test: Erzeuge die Tests für die gefilterte Abfragen
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||
|
||||
use Codeception\Example;
|
||||
use Codeception\Test\Unit;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
@@ -10,6 +11,7 @@ use InvalidArgumentException;
|
||||
use PDO;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryBadWhereDataException;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordAlreadyExistException;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursRepository;
|
||||
@@ -22,7 +24,7 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
const NEW_INTERVAL = 'PT7H59M';
|
||||
const RECORDS_COUNT = 61;
|
||||
|
||||
protected PDO $pdoObject;
|
||||
protected PDO $pdoObject;
|
||||
|
||||
protected function _before(): void
|
||||
{
|
||||
@@ -34,7 +36,7 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testFindAll(): void
|
||||
public function testFindAllWithBlankParameter(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$models = $repository->findAll();
|
||||
@@ -43,6 +45,81 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
$this->assertCount(self::RECORDS_COUNT, $models);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<int|string|null>>
|
||||
*/
|
||||
public function valideFilterParameter(): array
|
||||
{
|
||||
return [
|
||||
[null, null, 61,],
|
||||
['2020-04-01', null, 0,],
|
||||
['2020-04-01', '2020-04-30', 0,],
|
||||
[null, '2020-04-30', 61,],
|
||||
['2020-03-01', null, 22,],
|
||||
['2020-03-01', '2020-03-31', 22,],
|
||||
['2020-03-01', '2020-03-07', 5,],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $start
|
||||
* @param string|null $ende
|
||||
* @param int $count
|
||||
*
|
||||
* @dataProvider valideFilterParameter
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testFindAllWithValideParameter(?string $start, ?string $ende, int $count): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$models = $repository->findFiltered($start, $ende);
|
||||
$this->assertIsArray($models);
|
||||
$this->assertContainsOnly(WorkingHours::class, $models);
|
||||
$this->assertCount($count, $models);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<int|string|null>>
|
||||
*/
|
||||
public function invalideFilterParameter(): array
|
||||
{
|
||||
return [
|
||||
['2020-04-31',null],
|
||||
[null, '2020-04-31'],
|
||||
['2020-04-00','2020-04-31'],
|
||||
['2020-04-01','2020-04-31'],
|
||||
['2020-04-00','2020-04-30'],
|
||||
//
|
||||
['2020-04', null],
|
||||
[null, '2020-04'],
|
||||
['2020-04', '2020-04'],
|
||||
['2020-04-01','2020-04'],
|
||||
['2020-04', '2020-04-30'],
|
||||
//
|
||||
['2020', null],
|
||||
[null, '2020'],
|
||||
['2020', '2020'],
|
||||
['2020-04-01','2020'],
|
||||
['2020', '2020-04-30'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $start
|
||||
* @param string|null $ende
|
||||
*
|
||||
* @dataProvider invalideFilterParameter
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testFindAllWithInvalideParameter(?string $start, ?string $ende): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$this->expectException(RepositoryBadWhereDataException::class);
|
||||
$repository->findFiltered($start, $ende);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RepositoryRecordNotFoundException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user