171 lines
5.9 KiB
PHP
171 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
|
|
|
use Codeception\Attribute\DataProvider;
|
|
use Codeception\Test\Unit;
|
|
use DateInterval;
|
|
use DateTime;
|
|
use DateTimeInterface;
|
|
use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
|
|
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
|
|
|
class WorkingHoursViewTest extends Unit
|
|
{
|
|
|
|
/**
|
|
* @return array<array{DateTime,PeriodDesignationEnum,int,DateInterval,DateInterval,array<string,mixed>}>
|
|
*/
|
|
public function workingHoursProvider(): array
|
|
{
|
|
$date = new DateTime('2020-11-30');
|
|
$work_days = 15;
|
|
$home_work_days = 12;
|
|
$total_hours = new DateInterval("PT32H22M");
|
|
$overtime = new DateInterval("PT22M");
|
|
$absence_time = clone $overtime;
|
|
$absence_time->invert = 1;
|
|
return [
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::WEEKLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$overtime,
|
|
[
|
|
'period' => '2020#49',
|
|
'periodDesignation' => 'weekly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '00:22:00'
|
|
],
|
|
],
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::WEEKLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$absence_time,
|
|
[
|
|
'period' => '2020#49',
|
|
'periodDesignation' => 'weekly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '-00:22:00'
|
|
],
|
|
],
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::MONTHLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$overtime,
|
|
[
|
|
'period' => '2020-11',
|
|
'periodDesignation' => 'monthly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '00:22:00'
|
|
],
|
|
],
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::MONTHLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$absence_time,
|
|
[
|
|
'period' => '2020-11',
|
|
'periodDesignation' => 'monthly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '-00:22:00'
|
|
],
|
|
],
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::YEARLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$overtime,
|
|
[
|
|
'period' => '2020',
|
|
'periodDesignation' => 'yearly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '00:22:00'
|
|
],
|
|
],
|
|
[
|
|
$date,
|
|
PeriodDesignationEnum::YEARLY,
|
|
$work_days,
|
|
$total_hours,
|
|
$home_work_days,
|
|
$absence_time,
|
|
[
|
|
'period' => '2020',
|
|
'periodDesignation' => 'yearly',
|
|
'workingDays' => 15,
|
|
'totalHours' => '32:22:00',
|
|
'homeOfficeDays' => $home_work_days,
|
|
'overtime' => '-00:22:00'
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param DateTimeInterface $period
|
|
* @param PeriodDesignationEnum $periodDesignation
|
|
* @param int $workingDays
|
|
* @param DateInterval $totalHours
|
|
* @param int $homeWorkDays ,
|
|
* @param DateInterval $overtime
|
|
* @param array<string, string> $shouldJson
|
|
*/
|
|
#[DataProvider('workingHoursProvider')]
|
|
public function testWorkingHoursViewWithContent(
|
|
DateTimeInterface $period,
|
|
PeriodDesignationEnum $periodDesignation,
|
|
int $workingDays,
|
|
DateInterval $totalHours,
|
|
int $homeWorkDays,
|
|
DateInterval $overtime,
|
|
array $shouldJson
|
|
): void {
|
|
$obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $homeWorkDays, $overtime);
|
|
|
|
$this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod());
|
|
$this->assertEquals($period, $obj->getPeriod());
|
|
|
|
$this->assertInstanceOf(PeriodDesignationEnum::class, $obj->getPeriodDesignation());
|
|
$this->assertEquals($periodDesignation, $obj->getPeriodDesignation());
|
|
|
|
$this->assertEquals($workingDays, $obj->getWorkingDays());
|
|
|
|
$this->assertInstanceOf(DateInterval::class, $obj->getTotalHours());
|
|
$this->assertEquals($totalHours, $obj->getTotalHours());
|
|
|
|
$this->assertIsInt($obj->getHomeOfficeDays());
|
|
$this->assertEquals($homeWorkDays, $obj->getHomeOfficeDays());
|
|
|
|
$this->assertInstanceOf(DateInterval::class, $obj->getOvertime());
|
|
$this->assertEquals($overtime, $obj->getOvertime());
|
|
|
|
|
|
$json = $obj->jsonSerialize();
|
|
$this->assertEquals($shouldJson, $json);
|
|
}
|
|
}
|