Erweitere die Tests

This commit is contained in:
2025-06-19 14:19:09 +02:00
parent a964663f51
commit cf6eff6ab0
9 changed files with 195 additions and 44 deletions
+9 -1
View File
@@ -4,7 +4,7 @@
"title": "Zeiterfassung App", "title": "Zeiterfassung App",
"contact": { "contact": {
"name": "Torsten Lücke", "name": "Torsten Lücke",
"url": "http://torsten-hettstedt.de", "url": "https://torsten-hettstedt.de",
"email": "arbeit@torsten-hettstedt.de" "email": "arbeit@torsten-hettstedt.de"
}, },
"license": { "license": {
@@ -188,6 +188,10 @@
"type": "string", "type": "string",
"pattern": "[0-5]\\d:[0-5]\\d:[0-5]\\d", "pattern": "[0-5]\\d:[0-5]\\d:[0-5]\\d",
"example": "08:01:00" "example": "08:01:00"
},
"isHomeOffice": {
"description": "Wurde an diesem Tag zuhause gearbeitet?",
"type": "boolean"
} }
} }
}, },
@@ -217,6 +221,10 @@
"description": "Arbeitstage im Zeitraum", "description": "Arbeitstage im Zeitraum",
"type": "integer" "type": "integer"
}, },
"homeOfficeDays": {
"description": "Anzahl der Tage, an denen zuhause gearbeitet wurde.",
"type": "number"
},
"overtime": { "overtime": {
"description": "Überstunden im Zeitraum", "description": "Überstunden im Zeitraum",
"type": "string", "type": "string",
+3
View File
@@ -1,4 +1,5 @@
<?php <?php
namespace Helper; namespace Helper;
// here you can define custom actions // here you can define custom actions
@@ -15,6 +16,7 @@ class Api extends Module
const WORKING_HOURS_JSON_FORMAT = [ const WORKING_HOURS_JSON_FORMAT = [
'workingDay' => self::FORMAT_DATE, 'workingDay' => self::FORMAT_DATE,
'workingTime' => self::FORMAT_TIME, 'workingTime' => self::FORMAT_TIME,
'isHomeOffice' => 'boolean',
]; ];
const WORKING_HOURS_VIEW_JSON_FORMAT = [ const WORKING_HOURS_VIEW_JSON_FORMAT = [
@@ -22,6 +24,7 @@ class Api extends Module
"periodDesignation" => "string", "periodDesignation" => "string",
"totalHours" => self::FORMAT_TIME, "totalHours" => self::FORMAT_TIME,
"workingDays" => 'integer:>0', "workingDays" => 'integer:>0',
'homeOfficeDays' => 'number:>=0',
"overtime" => self::FORMAT_TIME, "overtime" => self::FORMAT_TIME,
]; ];
@@ -28,6 +28,7 @@ class CreateWorkingHoursCest
$I->sendPost('/working-hours', [ $I->sendPost('/working-hours', [
'workingDay' => '2020-04-01', 'workingDay' => '2020-04-01',
'workingTime' => '08:00:00', 'workingTime' => '08:00:00',
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::CREATED); $I->seeResponseCodeIs(HttpCode::CREATED);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -44,6 +45,7 @@ class CreateWorkingHoursCest
$I->sendPost('/working-hours', [ $I->sendPost('/working-hours', [
'workingDay' => '2020-04-01', 'workingDay' => '2020-04-01',
'workingTime' => 8.0, 'workingTime' => 8.0,
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -60,6 +62,7 @@ class CreateWorkingHoursCest
$I->sendPost('/working-hours', [ $I->sendPost('/working-hours', [
'workingDay' => '2020-01-15', 'workingDay' => '2020-01-15',
'workingTime' => '08:00:00', 'workingTime' => '08:00:00',
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::CONFLICT); $I->seeResponseCodeIs(HttpCode::CONFLICT);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -1,4 +1,5 @@
<?php /** @noinspection PhpUnused */ <?php
/** @noinspection PhpUnused */
namespace TorstenHettstedt\TimekeepingApi\Tests\Api\WorkingHours; namespace TorstenHettstedt\TimekeepingApi\Tests\Api\WorkingHours;
@@ -28,6 +29,7 @@ class UpdateWorkingHoursCest
$I->sendPut('/working-hours/2020-01-15', [ $I->sendPut('/working-hours/2020-01-15', [
'workingDay' => '2020-01-15', 'workingDay' => '2020-01-15',
'workingTime' => '10:00:00', 'workingTime' => '10:00:00',
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::OK); $I->seeResponseCodeIs(HttpCode::OK);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -43,6 +45,7 @@ class UpdateWorkingHoursCest
$I->sendPut('/working-hours/2020-04-15', [ $I->sendPut('/working-hours/2020-04-15', [
'workingDay' => '2020-04-15', 'workingDay' => '2020-04-15',
'workingTime' => '10:00:00', 'workingTime' => '10:00:00',
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::NOT_FOUND); $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -58,6 +61,7 @@ class UpdateWorkingHoursCest
$I->sendPut('/working-hours/2020-01-15', [ $I->sendPut('/working-hours/2020-01-15', [
'workingDay' => '2020-01-15', 'workingDay' => '2020-01-15',
'workingTime' => 8.0, 'workingTime' => 8.0,
'isHomeOffice' => false,
]); ]);
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
$I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN); $I->canSeeHttpHeader('Access-Control-Allow-Origin', Api::TEST_ORIGIN);
@@ -34,6 +34,7 @@ class WorkingHoursControllerTest extends AbstractControllerTest
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
'isHomeOfficeDay' => true,
], ],
]); ]);
} }
@@ -260,6 +261,28 @@ class WorkingHoursControllerTest extends AbstractControllerTest
$this->assertNotEmpty($response->getBody()->getContents()); $this->assertNotEmpty($response->getBody()->getContents());
} }
/**
* @throws ContainerExceptionInterface
* @throws NotDatabasesException
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function testUpdateExistRecordWithoutHomeOffice(): void
{
$this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [
'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL,
],
]);
$controller = new WorkingHoursController($this->container);
$response = $controller->update($this->request, $this->response, [
'id' => self::EXISTING_DATE,
]);
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
$this->assertNotEmpty($response->getBody()->getContents());
}
/** /**
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotDatabasesException * @throws NotDatabasesException
@@ -302,12 +325,13 @@ class WorkingHoursControllerTest extends AbstractControllerTest
* @throws Exception * @throws Exception
*/ */
#[DataProvider('invalidCreatDataProvider')] #[DataProvider('invalidCreatDataProvider')]
public function testCreatInvalidData(string $date, string $time): void public function testCreatInvalidData(string $date, string $time, bool $isHomeOffice = false): void
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => $date, 'workingDay' => $date,
'workingTime' => $time, 'workingTime' => $time,
'isHomeOfficeDay' => $isHomeOffice,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
@@ -322,6 +346,27 @@ class WorkingHoursControllerTest extends AbstractControllerTest
* @throws Exception * @throws Exception
*/ */
public function testCreatNewRecord(): void public function testCreatNewRecord(): void
{
$this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [
'workingDay' => self::NEW_DATE,
'workingTime' => self::NEW_INTERVAL,
'isHomeOfficeDay' => true,
],
]);
$controller = new WorkingHoursController($this->container);
$response = $controller->creat($this->request, $this->response, []);
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
$this->assertNotEmpty($response->getBody()->getContents());
}
/**
* @throws ContainerExceptionInterface
* @throws NotDatabasesException
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function testCreatNewRecordWithoutHomeOffice(): void
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
@@ -347,6 +392,7 @@ class WorkingHoursControllerTest extends AbstractControllerTest
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
'isHomeOfficeDay' => true,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
+37 -1
View File
@@ -17,6 +17,7 @@ class WorkingHoursTest extends Unit
$obj = new WorkingHours(); $obj = new WorkingHours();
$this->assertNull($obj->getWorkingDay()); $this->assertNull($obj->getWorkingDay());
$this->assertNull($obj->getWorkingTime()); $this->assertNull($obj->getWorkingTime());
$this->assertFalse($obj->isHomeOffice());
$this->expectException(Error::class); $this->expectException(Error::class);
$obj->jsonSerialize(); $obj->jsonSerialize();
@@ -34,7 +35,9 @@ class WorkingHoursTest extends Unit
[ [
'workingDay' => '2020-11-30', 'workingDay' => '2020-11-30',
'workingTime' => '08:00:00', 'workingTime' => '08:00:00',
'isHomeOffice' => true,
], ],
true,
], ],
[ [
new DateTime('2021-05-03'), new DateTime('2021-05-03'),
@@ -42,7 +45,9 @@ class WorkingHoursTest extends Unit
[ [
'workingDay' => '2021-05-03', 'workingDay' => '2021-05-03',
'workingTime' => '07:45:00', 'workingTime' => '07:45:00',
'isHomeOffice' => false,
], ],
false,
], ],
]; ];
} }
@@ -51,10 +56,38 @@ class WorkingHoursTest extends Unit
* @param DateTime $date * @param DateTime $date
* @param DateInterval $interval * @param DateInterval $interval
* @param array<string, string> $shouldJson * @param array<string, string> $shouldJson
* @param bool $isHomeOffice
*/ */
#[DataProvider('workingHoursProvider')] #[DataProvider('workingHoursProvider')]
public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $shouldJson): void public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $shouldJson, bool $isHomeOffice): void
{ {
$obj = new WorkingHours();
$obj->setWorkingDay($date)->setWorkingTime($interval)->setIsHomeOffice($isHomeOffice);
$this->assertNotNull($obj->getWorkingDay());
$this->assertInstanceOf(DateTime::class, $obj->getWorkingDay());
$this->assertEquals($date, $obj->getWorkingDay());
$this->assertNotNull($obj->getWorkingTime());
$this->assertInstanceOf(DateInterval::class, $obj->getWorkingTime());
$this->assertEquals($interval, $obj->getWorkingTime());
$this->assertIsBool($obj->isHomeOffice());
$this->assertEquals($isHomeOffice, $obj->isHomeOffice());
$json = $obj->jsonSerialize();
$this->assertEquals($shouldJson, $json);
}
/**
* @param DateTime $date
* @param DateInterval $interval
* @param array<string, string> $shouldJson
*/
#[DataProvider('workingHoursProvider')]
public function testWorkingHoursWithContentWithoutHomeOfficeInformation(DateTime $date, DateInterval $interval, array $shouldJson): void
{
$shouldJson['isHomeOffice'] = false;
$obj = new WorkingHours(); $obj = new WorkingHours();
$obj->setWorkingDay($date)->setWorkingTime($interval); $obj->setWorkingDay($date)->setWorkingTime($interval);
@@ -66,6 +99,9 @@ class WorkingHoursTest extends Unit
$this->assertInstanceOf(DateInterval::class, $obj->getWorkingTime()); $this->assertInstanceOf(DateInterval::class, $obj->getWorkingTime());
$this->assertEquals($interval, $obj->getWorkingTime()); $this->assertEquals($interval, $obj->getWorkingTime());
$this->assertIsBool($obj->isHomeOffice());
$this->assertFalse($obj->isHomeOffice());
$json = $obj->jsonSerialize(); $json = $obj->jsonSerialize();
$this->assertEquals($shouldJson, $json); $this->assertEquals($shouldJson, $json);
} }
+19 -1
View File
@@ -20,6 +20,7 @@ class WorkingHoursViewTest extends Unit
{ {
$date = new DateTime('2020-11-30'); $date = new DateTime('2020-11-30');
$work_days = 15; $work_days = 15;
$home_work_days = 12;
$total_hours = new DateInterval("PT32H22M"); $total_hours = new DateInterval("PT32H22M");
$overtime = new DateInterval("PT22M"); $overtime = new DateInterval("PT22M");
$absence_time = clone $overtime; $absence_time = clone $overtime;
@@ -30,12 +31,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::WEEKLY, PeriodDesignationEnum::WEEKLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$overtime, $overtime,
[ [
'period' => '2020#49', 'period' => '2020#49',
'periodDesignation' => 'weekly', 'periodDesignation' => 'weekly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '00:22:00' 'overtime' => '00:22:00'
], ],
], ],
@@ -44,12 +47,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::WEEKLY, PeriodDesignationEnum::WEEKLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$absence_time, $absence_time,
[ [
'period' => '2020#49', 'period' => '2020#49',
'periodDesignation' => 'weekly', 'periodDesignation' => 'weekly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '-00:22:00' 'overtime' => '-00:22:00'
], ],
], ],
@@ -58,12 +63,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::MONTHLY, PeriodDesignationEnum::MONTHLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$overtime, $overtime,
[ [
'period' => '2020-11', 'period' => '2020-11',
'periodDesignation' => 'monthly', 'periodDesignation' => 'monthly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '00:22:00' 'overtime' => '00:22:00'
], ],
], ],
@@ -72,12 +79,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::MONTHLY, PeriodDesignationEnum::MONTHLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$absence_time, $absence_time,
[ [
'period' => '2020-11', 'period' => '2020-11',
'periodDesignation' => 'monthly', 'periodDesignation' => 'monthly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '-00:22:00' 'overtime' => '-00:22:00'
], ],
], ],
@@ -86,12 +95,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::YEARLY, PeriodDesignationEnum::YEARLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$overtime, $overtime,
[ [
'period' => '2020', 'period' => '2020',
'periodDesignation' => 'yearly', 'periodDesignation' => 'yearly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '00:22:00' 'overtime' => '00:22:00'
], ],
], ],
@@ -100,12 +111,14 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum::YEARLY, PeriodDesignationEnum::YEARLY,
$work_days, $work_days,
$total_hours, $total_hours,
$home_work_days,
$absence_time, $absence_time,
[ [
'period' => '2020', 'period' => '2020',
'periodDesignation' => 'yearly', 'periodDesignation' => 'yearly',
'workingDays' => 15, 'workingDays' => 15,
'totalHours' => '32:22:00', 'totalHours' => '32:22:00',
'homeOfficeDays' => $home_work_days,
'overtime' => '-00:22:00' 'overtime' => '-00:22:00'
], ],
], ],
@@ -117,6 +130,7 @@ class WorkingHoursViewTest extends Unit
* @param PeriodDesignationEnum $periodDesignation * @param PeriodDesignationEnum $periodDesignation
* @param int $workingDays * @param int $workingDays
* @param DateInterval $totalHours * @param DateInterval $totalHours
* @param int $homeWorkDays ,
* @param DateInterval $overtime * @param DateInterval $overtime
* @param array<string, string> $shouldJson * @param array<string, string> $shouldJson
*/ */
@@ -126,10 +140,11 @@ class WorkingHoursViewTest extends Unit
PeriodDesignationEnum $periodDesignation, PeriodDesignationEnum $periodDesignation,
int $workingDays, int $workingDays,
DateInterval $totalHours, DateInterval $totalHours,
int $homeWorkDays,
DateInterval $overtime, DateInterval $overtime,
array $shouldJson array $shouldJson
): void { ): void {
$obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $overtime); $obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $homeWorkDays, $overtime);
$this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod()); $this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod());
$this->assertEquals($period, $obj->getPeriod()); $this->assertEquals($period, $obj->getPeriod());
@@ -142,6 +157,9 @@ class WorkingHoursViewTest extends Unit
$this->assertInstanceOf(DateInterval::class, $obj->getTotalHours()); $this->assertInstanceOf(DateInterval::class, $obj->getTotalHours());
$this->assertEquals($totalHours, $obj->getTotalHours()); $this->assertEquals($totalHours, $obj->getTotalHours());
$this->assertIsInt($obj->getHomeOfficeDays());
$this->assertEquals($homeWorkDays, $obj->getHomeOfficeDays());
$this->assertInstanceOf(DateInterval::class, $obj->getOvertime()); $this->assertInstanceOf(DateInterval::class, $obj->getOvertime());
$this->assertEquals($overtime, $obj->getOvertime()); $this->assertEquals($overtime, $obj->getOvertime());
@@ -159,6 +159,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::NEW_DATE), 'workingDay' => new DateTime(self::NEW_DATE),
'workingTime' => new DateInterval(self::NEW_INTERVAL), 'workingTime' => new DateInterval(self::NEW_INTERVAL),
'isHomeOffice' => false,
]); ]);
$repository->insert($model); $repository->insert($model);
$model = $repository->findByKey(self::NEW_DATE); $model = $repository->findByKey(self::NEW_DATE);
@@ -176,6 +177,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::EXISTING_DATE), 'workingDay' => new DateTime(self::EXISTING_DATE),
'workingTime' => new DateInterval(self::NEW_INTERVAL), 'workingTime' => new DateInterval(self::NEW_INTERVAL),
'isHomeOffice' => false,
]); ]);
$this->expectException(RepositoryRecordAlreadyExistException::class); $this->expectException(RepositoryRecordAlreadyExistException::class);
$repository->insert($model); $repository->insert($model);
@@ -203,6 +205,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::EXISTING_DATE), 'workingDay' => new DateTime(self::EXISTING_DATE),
'workingTime' => new DateInterval(self::EXISTING_INTERVAL), 'workingTime' => new DateInterval(self::EXISTING_INTERVAL),
'isHomeOffice' => false,
]); ]);
$repository->delete($model); $repository->delete($model);
$this->expectException(RepositoryRecordNotFoundException::class); $this->expectException(RepositoryRecordNotFoundException::class);
@@ -219,6 +222,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::NEW_DATE), 'workingDay' => new DateTime(self::NEW_DATE),
'workingTime' => new DateInterval(self::NEW_INTERVAL), 'workingTime' => new DateInterval(self::NEW_INTERVAL),
'isHomeOffice' => false,
]); ]);
$this->expectException(RepositoryRecordNotFoundException::class); $this->expectException(RepositoryRecordNotFoundException::class);
$repository->delete($model); $repository->delete($model);
@@ -246,6 +250,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::EXISTING_DATE), 'workingDay' => new DateTime(self::EXISTING_DATE),
'workingTime' => new DateInterval(self::NEW_INTERVAL), 'workingTime' => new DateInterval(self::NEW_INTERVAL),
'isHomeOffice' => false,
]); ]);
$repository->update($model); $repository->update($model);
$model_db = $repository->findByKey(self::EXISTING_DATE); $model_db = $repository->findByKey(self::EXISTING_DATE);
@@ -261,6 +266,7 @@ class WorkingHoursRepositoryTest extends Unit
$model = $this->make(WorkingHours::class, [ $model = $this->make(WorkingHours::class, [
'workingDay' => new DateTime(self::NEW_DATE), 'workingDay' => new DateTime(self::NEW_DATE),
'workingTime' => new DateInterval(self::NEW_INTERVAL), 'workingTime' => new DateInterval(self::NEW_INTERVAL),
'isHomeOffice' => false,
]); ]);
$this->expectException(RepositoryRecordNotFoundException::class); $this->expectException(RepositoryRecordNotFoundException::class);
$repository->update($model); $repository->update($model);
@@ -6,7 +6,8 @@ use Codeception\Attribute\DataProvider;
use Codeception\Test\Unit; use Codeception\Test\Unit;
use DateTime; use DateTime;
use DateTimeZone; 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\RepositoryRecordNotFoundException;
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursWeeklyViewRepository; use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursWeeklyViewRepository;
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursMonthlyViewRepository; use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursMonthlyViewRepository;
@@ -19,7 +20,9 @@ class WorkingHoursViewRepositoryTest extends Unit
protected function _before(): void protected function _before(): void
{ {
/** @noinspection SpellCheckingInspection */ /** @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(); parent::_before();
} }
@@ -41,9 +44,27 @@ class WorkingHoursViewRepositoryTest extends Unit
public function existingObjectProvider(): array public function existingObjectProvider(): array
{ {
return [ 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'))], WorkingHoursYearlyViewRepository::class,
[WorkingHoursWeeklyViewRepository::class, '2020#03', 5, date_create('2020-01-13', new DateTimeZone('UCT'))], '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,
],
]; ];
} }
@@ -70,13 +91,19 @@ class WorkingHoursViewRepositoryTest extends Unit
} }
#[DataProvider(('existingObjectProvider'))] #[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); $repository = new $periodClass($this->pdoObject);
$model = $repository->findByKey($search); $model = $repository->findByKey($search);
$this->assertInstanceOf(WorkingHoursView::class, $model); $this->assertInstanceOf(WorkingHoursView::class, $model);
$this->assertEquals($workingDays, $model->getWorkingDays()); $this->assertEquals($workingDays, $model->getWorkingDays());
$this->assertEquals($period->format('Ymd'), $model->getPeriod()->format('Ymd')); $this->assertEquals($period->format('Ymd'), $model->getPeriod()->format('Ymd'));
$this->assertEquals($homeOfficeDays, $model->getHomeOfficeDays());
} }
#[DataProvider(('notExistingObjectProvider'))] #[DataProvider(('notExistingObjectProvider'))]