From 0bd8932fa1102ca6b538c1728d3da1dca93e5dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 15 Apr 2021 11:28:47 +0200 Subject: [PATCH 1/4] Es wurde sich auf Functions-Tests verlassen. --- .../unit/Middleware/ErrorHandlerTest.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/api/tests/unit/Middleware/ErrorHandlerTest.php b/api/tests/unit/Middleware/ErrorHandlerTest.php index b1c842e..1c4e9d5 100644 --- a/api/tests/unit/Middleware/ErrorHandlerTest.php +++ b/api/tests/unit/Middleware/ErrorHandlerTest.php @@ -12,6 +12,9 @@ use Psr\Http\Message\StreamInterface; use Psr\Log\LoggerInterface; use Slim\App; use Slim\Exception\HttpException; +use Slim\Interfaces\RouteParserInterface; +use Slim\Routing\RouteContext; +use Slim\Routing\RoutingResults; use TorstenHettstedt\TimekeepingApi\Middleware\ErrorHandler; class ErrorHandlerTest extends Unit @@ -28,6 +31,7 @@ class ErrorHandlerTest extends Unit protected function _before(): void { parent::_before(); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->app = $this->makeEmpty(App::class, [ 'getResponseFactory' => $this->makeEmpty(ResponseFactoryInterface::class, [ 'createResponse' => $this->makeEmpty(ResponseInterface::class, [ @@ -40,7 +44,16 @@ class ErrorHandlerTest extends Unit ]), ]), ]); - $this->request = $this->makeEmpty(ServerRequestInterface::class); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ + $this->request = $this->makeEmpty(ServerRequestInterface::class, [ + 'getAttribute' => function($name) { + return match ($name) { + RouteContext::ROUTE_PARSER => $this->makeEmpty(RouteParserInterface::class), + RouteContext::ROUTING_RESULTS => $this->makeEmpty(RoutingResults::class), + default => null, + }; + } + ]); } /** @@ -48,11 +61,13 @@ class ErrorHandlerTest extends Unit */ public function testUseWithLogger(): void { + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(Exception::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', ]); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, [ 'error' => Expected::once(), ]); @@ -66,12 +81,14 @@ class ErrorHandlerTest extends Unit */ public function testUseWithHttpException(): void { + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(HttpException::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', 'getTitle' => Expected::once('The Title'), ]); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, []); $middleWare = new ErrorHandler($this->app); @@ -84,11 +101,13 @@ class ErrorHandlerTest extends Unit */ public function testUseWithGeneralException(): void { + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(Exception::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', ]); + /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, []); $middleWare = new ErrorHandler($this->app); -- 2.54.0 From 735b195c06cbaef4c977b6732fa205232aa1ca21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 15 Apr 2021 11:34:04 +0200 Subject: [PATCH 2/4] Die Tests hatten nicht die richtige Darstellung von negativen Werten getestet. --- .../unit/Models/WorkingHoursViewTest.php | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/api/tests/unit/Models/WorkingHoursViewTest.php b/api/tests/unit/Models/WorkingHoursViewTest.php index d26c055..cf0a0db 100644 --- a/api/tests/unit/Models/WorkingHoursViewTest.php +++ b/api/tests/unit/Models/WorkingHoursViewTest.php @@ -17,13 +17,15 @@ class WorkingHoursViewTest extends Unit */ public function workingHoursProvider(): array { + $date = new DateTime('2020-11-30'); + $work_days = 15; + $total_hours = new DateInterval("PT32H22M"); + $overtime = new DateInterval("PT22M"); + $absence_time = clone $overtime; + $absence_time->invert = 1; return [ [ - new DateTime('2020-11-30'), - PeriodDesignationEnum::WEEKLY(), - 15, - new DateInterval("PT32H22M"), - new DateInterval("PT22M"), + $date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $overtime, [ 'period' => '2020#49', 'periodDesignation' => 'weekly', @@ -33,11 +35,17 @@ class WorkingHoursViewTest extends Unit ], ], [ - new DateTime('2020-11-30'), - PeriodDesignationEnum::MONTHLY(), - 15, - new DateInterval("PT32H22M"), - new DateInterval("PT22M"), + $date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $absence_time, + [ + 'period' => '2020#49', + 'periodDesignation' => 'weekly', + 'workingDays' => 15, + 'totalHours' => '32:22:00', + 'overtime' => '-00:22:00' + ], + ], + [ + $date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $overtime, [ 'period' => '2020-11', 'periodDesignation' => 'monthly', @@ -47,12 +55,17 @@ class WorkingHoursViewTest extends Unit ], ], [ - new DateTime('2020-11-30'), - PeriodDesignationEnum::YEARLY(), - 15, - new DateInterval("PT32H22M"), - new DateInterval("PT22M"), + $date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $absence_time, [ + 'period' => '2020-11', + 'periodDesignation' => 'monthly', + 'workingDays' => 15, + 'totalHours' => '32:22:00', + 'overtime' => '-00:22:00' + ], + ], + [ + $date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $overtime, [ 'period' => '2020', 'periodDesignation' => 'yearly', 'workingDays' => 15, @@ -60,6 +73,15 @@ class WorkingHoursViewTest extends Unit 'overtime' => '00:22:00' ], ], + [ + $date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $absence_time, [ + 'period' => '2020', + 'periodDesignation' => 'yearly', + 'workingDays' => 15, + 'totalHours' => '32:22:00', + 'overtime' => '-00:22:00' + ], + ], ]; } -- 2.54.0 From 2b2753e0096bad058357a6950a2159dc99edc688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 15 Apr 2021 11:34:50 +0200 Subject: [PATCH 3/4] Die Darstellung von negativen Werten erfolgt richtig. --- api/src/Models/WorkingHoursView.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/Models/WorkingHoursView.php b/api/src/Models/WorkingHoursView.php index fdfa397..b229ec8 100644 --- a/api/src/Models/WorkingHoursView.php +++ b/api/src/Models/WorkingHoursView.php @@ -91,12 +91,13 @@ class WorkingHoursView implements ModelInterface 'overtime' => "string" ])] public function jsonSerialize(): array { + $formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S'; return [ 'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()), 'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()), 'workingDays' => $this->getWorkingDays(), 'totalHours' => $this->getTotalHours()->format('%H:%I:%S'), - 'overtime' => $this->getOvertime()->format('%H:%I:%S') + 'overtime' => $this->getOvertime()->format($formatOvertime) ]; } } \ No newline at end of file -- 2.54.0 From cc9941d1d3bc340bc5e52541da7548c5049d09f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 15 Apr 2021 12:23:22 +0200 Subject: [PATCH 4/4] Negative Werte werden deutlich dargestellt. --- ui/public/less/lesslib/colors.less | 1 + ui/public/less/lesslib/layout.less | 7 +++++++ ui/src/routes/Views.svelte | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ui/public/less/lesslib/colors.less b/ui/public/less/lesslib/colors.less index beab906..bdcae0f 100644 --- a/ui/public/less/lesslib/colors.less +++ b/ui/public/less/lesslib/colors.less @@ -6,6 +6,7 @@ Definition der Farben @hueSub: 215; @mainColor: hsl(@hueMain, 90%, 29%); +@redColor: hsl(0, 90%, 29%); @mainColorDark: darken(@mainColor,66%,relativ); @mainColorLight: lighten(@mainColor,66%,relativ); @subColor: hsl(@hueSub, 90%, 29%); diff --git a/ui/public/less/lesslib/layout.less b/ui/public/less/lesslib/layout.less index 50f30b2..ab1e143 100644 --- a/ui/public/less/lesslib/layout.less +++ b/ui/public/less/lesslib/layout.less @@ -79,6 +79,13 @@ main { border-bottom: @mainColor solid thin; } } + }; + tbody { + td.absence-time { + color: @redColor; + text-decoration-line: underline; + text-decoration-style: dashed; + } } } form { diff --git a/ui/src/routes/Views.svelte b/ui/src/routes/Views.svelte index 5401f0b..0a665a2 100644 --- a/ui/src/routes/Views.svelte +++ b/ui/src/routes/Views.svelte @@ -1,6 +1,14 @@ @@ -36,7 +44,7 @@ {record.period} {record.workingDays} {record.totalHours} - {record.overtime} + {cutMinusChar(record.overtime)} {/each} -- 2.54.0