Refactor Tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
||||
|
||||
use Codeception\Attribute\DataProvider;
|
||||
use Codeception\Test\Unit;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
@@ -22,7 +23,7 @@ class WorkingHoursTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<array<DateTime|DateInterval|array<string,string>>>
|
||||
*/
|
||||
public function workingHoursProvider(): array
|
||||
{
|
||||
@@ -49,17 +50,13 @@ class WorkingHoursTest extends Unit
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @param DateInterval $interval
|
||||
* @param array<string, string> $should_json
|
||||
*
|
||||
* @dataProvider workingHoursProvider
|
||||
* @param array<string, string> $shouldJson
|
||||
*/
|
||||
public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $should_json): void
|
||||
#[DataProvider('workingHoursProvider')]
|
||||
public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $shouldJson): void
|
||||
{
|
||||
|
||||
$obj = new WorkingHours();
|
||||
$obj
|
||||
->setWorkingDay($date)
|
||||
->setWorkingTime($interval);
|
||||
$obj->setWorkingDay($date)->setWorkingTime($interval);
|
||||
|
||||
$this->assertNotNull($obj->getWorkingDay());
|
||||
$this->assertInstanceOf(DateTime::class, $obj->getWorkingDay());
|
||||
@@ -70,7 +67,6 @@ class WorkingHoursTest extends Unit
|
||||
$this->assertEquals($interval, $obj->getWorkingTime());
|
||||
|
||||
$json = $obj->jsonSerialize();
|
||||
$this->assertIsArray($json);
|
||||
$this->assertEquals($should_json, $json);
|
||||
$this->assertEquals($shouldJson, $json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
||||
|
||||
use Codeception\Attribute\DataProvider;
|
||||
use Codeception\Test\Unit;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
@@ -13,7 +14,7 @@ class WorkingHoursViewTest extends Unit
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<array{DateTime,PeriodDesignationEnum,int,DateInterval,DateInterval,array<string,mixed>}>
|
||||
*/
|
||||
public function workingHoursProvider(): array
|
||||
{
|
||||
@@ -25,7 +26,11 @@ class WorkingHoursViewTest extends Unit
|
||||
$absence_time->invert = 1;
|
||||
return [
|
||||
[
|
||||
$date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $overtime,
|
||||
$date,
|
||||
PeriodDesignationEnum::WEEKLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$overtime,
|
||||
[
|
||||
'period' => '2020#49',
|
||||
'periodDesignation' => 'weekly',
|
||||
@@ -35,7 +40,11 @@ class WorkingHoursViewTest extends Unit
|
||||
],
|
||||
],
|
||||
[
|
||||
$date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $absence_time,
|
||||
$date,
|
||||
PeriodDesignationEnum::WEEKLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$absence_time,
|
||||
[
|
||||
'period' => '2020#49',
|
||||
'periodDesignation' => 'weekly',
|
||||
@@ -45,7 +54,11 @@ class WorkingHoursViewTest extends Unit
|
||||
],
|
||||
],
|
||||
[
|
||||
$date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $overtime,
|
||||
$date,
|
||||
PeriodDesignationEnum::MONTHLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$overtime,
|
||||
[
|
||||
'period' => '2020-11',
|
||||
'periodDesignation' => 'monthly',
|
||||
@@ -55,7 +68,11 @@ class WorkingHoursViewTest extends Unit
|
||||
],
|
||||
],
|
||||
[
|
||||
$date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $absence_time,
|
||||
$date,
|
||||
PeriodDesignationEnum::MONTHLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$absence_time,
|
||||
[
|
||||
'period' => '2020-11',
|
||||
'periodDesignation' => 'monthly',
|
||||
@@ -65,7 +82,12 @@ class WorkingHoursViewTest extends Unit
|
||||
],
|
||||
],
|
||||
[
|
||||
$date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $overtime, [
|
||||
$date,
|
||||
PeriodDesignationEnum::YEARLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$overtime,
|
||||
[
|
||||
'period' => '2020',
|
||||
'periodDesignation' => 'yearly',
|
||||
'workingDays' => 15,
|
||||
@@ -74,7 +96,12 @@ class WorkingHoursViewTest extends Unit
|
||||
],
|
||||
],
|
||||
[
|
||||
$date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $absence_time, [
|
||||
$date,
|
||||
PeriodDesignationEnum::YEARLY,
|
||||
$work_days,
|
||||
$total_hours,
|
||||
$absence_time,
|
||||
[
|
||||
'period' => '2020',
|
||||
'periodDesignation' => 'yearly',
|
||||
'workingDays' => 15,
|
||||
@@ -86,50 +113,40 @@ class WorkingHoursViewTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTimeInterface $period
|
||||
* @param PeriodDesignationEnum $periodDesignation
|
||||
* @param int $workingDays
|
||||
* @param DateInterval $totalHours
|
||||
* @param DateInterval $overtime
|
||||
* @param array<string, string> $should_json
|
||||
*
|
||||
* @dataProvider workingHoursProvider
|
||||
* @param DateTimeInterface $period
|
||||
* @param PeriodDesignationEnum $periodDesignation
|
||||
* @param int $workingDays
|
||||
* @param DateInterval $totalHours
|
||||
* @param DateInterval $overtime
|
||||
* @param array<string, string> $shouldJson
|
||||
*/
|
||||
#[DataProvider('workingHoursProvider')]
|
||||
public function testWorkingHoursViewWithContent(
|
||||
DateTimeInterface $period,
|
||||
PeriodDesignationEnum $periodDesignation,
|
||||
int $workingDays,
|
||||
DateInterval $totalHours,
|
||||
DateInterval $overtime,
|
||||
array $should_json
|
||||
): void
|
||||
{
|
||||
|
||||
array $shouldJson
|
||||
): void {
|
||||
$obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $overtime);
|
||||
|
||||
$this->assertNotNull($obj->getPeriod());
|
||||
$this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod());
|
||||
$this->assertEquals($period, $obj->getPeriod());
|
||||
|
||||
$this->assertNotNull($obj->getPeriodDesignation());
|
||||
$this->assertInstanceOf(PeriodDesignationEnum::class, $obj->getPeriodDesignation());
|
||||
$this->assertEquals($periodDesignation, $obj->getPeriodDesignation());
|
||||
|
||||
$this->assertNotNull($obj->getWorkingDays());
|
||||
$this->assertIsInt($obj->getWorkingDays());
|
||||
$this->assertEquals($workingDays, $obj->getWorkingDays());
|
||||
|
||||
$this->assertNotNull($obj->getTotalHours());
|
||||
$this->assertInstanceOf(DateInterval::class, $obj->getTotalHours());
|
||||
$this->assertEquals($totalHours, $obj->getTotalHours());
|
||||
|
||||
$this->assertNotNull($obj->getOvertime());
|
||||
$this->assertInstanceOf(DateInterval::class, $obj->getOvertime());
|
||||
$this->assertEquals($overtime, $obj->getOvertime());
|
||||
|
||||
|
||||
$json = $obj->jsonSerialize();
|
||||
$this->assertIsArray($json);
|
||||
$this->assertEquals($should_json, $json);
|
||||
$this->assertEquals($shouldJson, $json);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user