Erweitere die Tests
This commit is contained in:
@@ -157,8 +157,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$repository->insert($model);
|
||||
$model = $repository->findByKey(self::NEW_DATE);
|
||||
@@ -174,8 +175,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$this->expectException(RepositoryRecordAlreadyExistException::class);
|
||||
$repository->insert($model);
|
||||
@@ -201,8 +203,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::EXISTING_INTERVAL),
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::EXISTING_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$repository->delete($model);
|
||||
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||
@@ -217,8 +220,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||
$repository->delete($model);
|
||||
@@ -244,8 +248,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$repository->update($model);
|
||||
$model_db = $repository->findByKey(self::EXISTING_DATE);
|
||||
@@ -259,8 +264,9 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(WorkingHours::class, [
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
'isHomeOffice' => false,
|
||||
]);
|
||||
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||
$repository->update($model);
|
||||
|
||||
@@ -6,7 +6,8 @@ use Codeception\Attribute\DataProvider;
|
||||
use Codeception\Test\Unit;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use PDO;use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||
use PDO;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursWeeklyViewRepository;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursMonthlyViewRepository;
|
||||
@@ -14,12 +15,14 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursYearlyViewRepositor
|
||||
|
||||
class WorkingHoursViewRepositoryTest extends Unit
|
||||
{
|
||||
protected PDO $pdoObject;
|
||||
protected PDO $pdoObject;
|
||||
|
||||
protected function _before(): void
|
||||
{
|
||||
/** @noinspection SpellCheckingInspection */
|
||||
$this->pdoObject = new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass');
|
||||
$this->pdoObject = new PDO(
|
||||
'pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'
|
||||
);
|
||||
parent::_before();
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
public function listObjectProvider(): array
|
||||
{
|
||||
return [
|
||||
[WorkingHoursYearlyViewRepository::class, 1],
|
||||
[WorkingHoursYearlyViewRepository::class, 1],
|
||||
[WorkingHoursMonthlyViewRepository::class, 3],
|
||||
[WorkingHoursWeeklyViewRepository::class, 13],
|
||||
];
|
||||
@@ -41,9 +44,27 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
public function existingObjectProvider(): array
|
||||
{
|
||||
return [
|
||||
[WorkingHoursYearlyViewRepository::class, '2020', 61, date_create('2020-01-01', new DateTimeZone('UCT'))],
|
||||
[WorkingHoursMonthlyViewRepository::class, '2020 February', 20, date_create('2020-02-01', new DateTimeZone('UCT'))],
|
||||
[WorkingHoursWeeklyViewRepository::class, '2020#03', 5, date_create('2020-01-13', new DateTimeZone('UCT'))],
|
||||
[
|
||||
WorkingHoursYearlyViewRepository::class,
|
||||
'2020',
|
||||
61,
|
||||
date_create('2020-01-01', new DateTimeZone('UCT')),
|
||||
3,
|
||||
],
|
||||
[
|
||||
WorkingHoursMonthlyViewRepository::class,
|
||||
'2020 February',
|
||||
20,
|
||||
date_create('2020-02-01', new DateTimeZone('UCT')),
|
||||
1,
|
||||
],
|
||||
[
|
||||
WorkingHoursWeeklyViewRepository::class,
|
||||
'2020#03',
|
||||
5,
|
||||
date_create('2020-01-13', new DateTimeZone('UCT')),
|
||||
0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -53,9 +74,9 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
public function notExistingObjectProvider(): array
|
||||
{
|
||||
return [
|
||||
[WorkingHoursYearlyViewRepository::class, '2022',],
|
||||
[WorkingHoursYearlyViewRepository::class, '2022',],
|
||||
[WorkingHoursMonthlyViewRepository::class, '2020 May',],
|
||||
[WorkingHoursWeeklyViewRepository::class, '2020#30',],
|
||||
[WorkingHoursWeeklyViewRepository::class, '2020#30',],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,13 +91,19 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
}
|
||||
|
||||
#[DataProvider(('existingObjectProvider'))]
|
||||
public function testExistingFindByKey(string $periodClass, string $search, int $workingDays, DateTime $period): void
|
||||
{
|
||||
public function testExistingFindByKey(
|
||||
string $periodClass,
|
||||
string $search,
|
||||
int $workingDays,
|
||||
DateTime $period,
|
||||
int $homeOfficeDays
|
||||
): void {
|
||||
$repository = new $periodClass($this->pdoObject);
|
||||
$model = $repository->findByKey($search);
|
||||
$this->assertInstanceOf(WorkingHoursView::class, $model);
|
||||
$this->assertEquals($workingDays, $model->getWorkingDays());
|
||||
$this->assertEquals($period->format('Ymd'), $model->getPeriod()->format('Ymd'));
|
||||
$this->assertEquals($homeOfficeDays, $model->getHomeOfficeDays());
|
||||
}
|
||||
|
||||
#[DataProvider(('notExistingObjectProvider'))]
|
||||
|
||||
Reference in New Issue
Block a user