Compare commits
6
Commits
af61eb2334
...
6fa6b28af6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fa6b28af6 | ||
|
|
41a3c79c91 | ||
|
|
82aad9766e | ||
|
|
b094cf8180 | ||
|
|
dff3c7f34d | ||
|
|
aa66d1f53d |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM php:8.0-apache
|
FROM php:8.4-apache-bookworm
|
||||||
|
|
||||||
RUN apt update && apt install -y libpq-dev
|
RUN apt update && apt install -y libpq-dev
|
||||||
RUN docker-php-ext-install -j$(nproc) pdo pdo_pgsql
|
RUN docker-php-ext-install -j$(nproc) pdo pdo_pgsql
|
||||||
|
|||||||
+9
-8
@@ -16,21 +16,22 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
|
"php": "8.4.*",
|
||||||
"slim/slim": "^4.7.1",
|
"slim/slim": "^4.7.1",
|
||||||
"vlucas/phpdotenv": "^4.2",
|
"vlucas/phpdotenv": "^v5.6.1",
|
||||||
"slim/psr7": "^1.3",
|
"slim/psr7": "^1.7.0",
|
||||||
"php-di/slim-bridge": "^3.1.0",
|
"php-di/slim-bridge": "^3.1.0",
|
||||||
"jetbrains/phpstorm-attributes": "^1.0.0",
|
"jetbrains/phpstorm-attributes": "^1.0.0",
|
||||||
"myclabs/php-enum": "^1.8.0",
|
"myclabs/php-enum": "^1.8.0",
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpstan/phpstan": "^0.12.80",
|
"phpstan/phpstan": "^2.1.12",
|
||||||
"codeception/codeception": "^4.1.18",
|
"codeception/codeception": "^5.2.1",
|
||||||
"codeception/module-phpbrowser": "^1.0.0",
|
"codeception/module-phpbrowser": "^3.0.1",
|
||||||
"codeception/module-asserts": "^1.0.0",
|
"codeception/module-asserts": "^3.1.0",
|
||||||
"codeception/module-db": "^1.1.0",
|
"codeception/module-db": "^3.2.2",
|
||||||
"codeception/module-rest": "^1.2.8"
|
"codeception/module-rest": "^3.4.1"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ namespace TorstenHettstedt\TimekeepingApi\Controller;
|
|||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Slim\Psr7\Response;
|
use Slim\Psr7\Response;
|
||||||
|
|
||||||
abstract class AbstractController
|
abstract class AbstractController
|
||||||
@@ -18,6 +20,8 @@ abstract class AbstractController
|
|||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
*
|
*
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@@ -34,7 +38,8 @@ abstract class AbstractController
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
protected function printResponse(Response $response, mixed $data, int $status_code): Response {
|
protected function printResponse(Response $response, mixed $data, int $status_code): Response
|
||||||
|
{
|
||||||
$payload = json_encode($data);
|
$payload = json_encode($data);
|
||||||
|
|
||||||
$response->getBody()->write($payload);
|
$response->getBody()->write($payload);
|
||||||
|
|||||||
@@ -8,13 +8,8 @@ class HttpConflictRequestException extends HttpSpecializedException
|
|||||||
{
|
{
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $code = 409;
|
protected $code = 409;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $message = 'Conflict.';
|
protected $message = 'Conflict.';
|
||||||
|
protected string $title = '409 Conflict';
|
||||||
/** @var string */
|
protected string $description = 'The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource.';
|
||||||
protected $title = '409 Conflict';
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $description = 'The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource.';
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use TorstenHettstedt\TimekeepingApi\Middleware\OriginAccessControlHandler;
|
|||||||
|
|
||||||
class PreflightController
|
class PreflightController
|
||||||
{
|
{
|
||||||
|
/** @noinspection PhpUnused */
|
||||||
public function preflight(Request $request, Response $response): ResponseInterface
|
public function preflight(Request $request, Response $response): ResponseInterface
|
||||||
{
|
{
|
||||||
return (new OriginAccessControlHandler())->originAccessControl($request, $response);
|
return (new OriginAccessControlHandler())->originAccessControl($request, $response);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ class WorkingHoursController extends AbstractController
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -44,9 +44,9 @@ class WorkingHoursController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -59,21 +59,29 @@ class WorkingHoursController extends AbstractController
|
|||||||
$repository = new WorkingHoursRepository($this->databases);
|
$repository = new WorkingHoursRepository($this->databases);
|
||||||
$queryParams = $request->getQueryParams();
|
$queryParams = $request->getQueryParams();
|
||||||
try {
|
try {
|
||||||
return $this->printResponse($response, $repository->findFiltered(
|
return $this->printResponse(
|
||||||
$queryParams['start-date'] ?? null,
|
$response,
|
||||||
$queryParams['end-date'] ?? null
|
$repository->findFiltered(
|
||||||
), StatusCodeInterface::STATUS_OK);
|
$queryParams['start-date'] ?? null,
|
||||||
|
$queryParams['end-date'] ?? null
|
||||||
|
),
|
||||||
|
StatusCodeInterface::STATUS_OK
|
||||||
|
);
|
||||||
} catch (RepositoryBadWhereDataException $exception) {
|
} catch (RepositoryBadWhereDataException $exception) {
|
||||||
throw new HttpBadRequestException($request, 'Ein Wert für das Datum im Query ist ungültig', $exception);
|
throw new HttpBadRequestException($request, 'Ein Wert für das Datum im Query ist ungültig', $exception);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request, 'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
throw new HttpInternalServerErrorException(
|
||||||
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank',
|
||||||
|
$exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -88,14 +96,18 @@ class WorkingHoursController extends AbstractController
|
|||||||
} catch (RepositoryRecordNotFoundException $exception) {
|
} catch (RepositoryRecordNotFoundException $exception) {
|
||||||
throw new HttpNotFoundException($request, 'Der Eintrag ist nicht vorhanden.', $exception);
|
throw new HttpNotFoundException($request, 'Der Eintrag ist nicht vorhanden.', $exception);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request, 'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
throw new HttpInternalServerErrorException(
|
||||||
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank',
|
||||||
|
$exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -114,7 +126,11 @@ class WorkingHoursController extends AbstractController
|
|||||||
} catch (RepositoryRecordAlreadyExistException $exception) {
|
} catch (RepositoryRecordAlreadyExistException $exception) {
|
||||||
throw new HttpConflictRequestException($request, 'Der Eintrag ist schon vorhanden.', $exception);
|
throw new HttpConflictRequestException($request, 'Der Eintrag ist schon vorhanden.', $exception);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request, 'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
throw new HttpInternalServerErrorException(
|
||||||
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank',
|
||||||
|
$exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $this->printResponse($response, $model, StatusCodeInterface::STATUS_CREATED);
|
return $this->printResponse($response, $model, StatusCodeInterface::STATUS_CREATED);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursYearlyViewRepositor
|
|||||||
class WorkingHoursViewController extends AbstractController
|
class WorkingHoursViewController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -30,15 +30,17 @@ class WorkingHoursViewController extends AbstractController
|
|||||||
try {
|
try {
|
||||||
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request,
|
throw new HttpInternalServerErrorException(
|
||||||
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -51,15 +53,17 @@ class WorkingHoursViewController extends AbstractController
|
|||||||
try {
|
try {
|
||||||
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request,
|
throw new HttpInternalServerErrorException(
|
||||||
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param mixed[] $args
|
* @param array<string, mixed> $args
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
@@ -72,8 +76,10 @@ class WorkingHoursViewController extends AbstractController
|
|||||||
try {
|
try {
|
||||||
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
return $this->printResponse($response, $repository->findAll(), StatusCodeInterface::STATUS_OK);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new HttpInternalServerErrorException($request,
|
throw new HttpInternalServerErrorException(
|
||||||
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
|
$request,
|
||||||
|
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<?php /** @noinspection PhpUndefinedClassInspection */
|
<?php
|
||||||
|
/** @noinspection PhpUndefinedClassInspection */
|
||||||
|
|
||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Middleware;
|
namespace TorstenHettstedt\TimekeepingApi\Middleware;
|
||||||
|
|
||||||
|
|
||||||
use JetBrains\PhpStorm\ArrayShape;
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -14,12 +16,15 @@ use Throwable;
|
|||||||
|
|
||||||
class ErrorHandler
|
class ErrorHandler
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var App<ContainerInterface>
|
||||||
|
*/
|
||||||
protected App $app;
|
protected App $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ErrorHandler constructor.
|
* ErrorHandler constructor.
|
||||||
*
|
*
|
||||||
* @param App $app
|
* @param App<ContainerInterface> $app
|
||||||
*/
|
*/
|
||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
@@ -29,7 +34,7 @@ class ErrorHandler
|
|||||||
/**
|
/**
|
||||||
* @param Throwable $exception
|
* @param Throwable $exception
|
||||||
*
|
*
|
||||||
* @return mixed[]
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
#[ArrayShape([
|
#[ArrayShape([
|
||||||
'timestamp' => "false|string",
|
'timestamp' => "false|string",
|
||||||
@@ -71,8 +76,7 @@ class ErrorHandler
|
|||||||
bool $logErrors,
|
bool $logErrors,
|
||||||
bool $logErrorDetails,
|
bool $logErrorDetails,
|
||||||
?LoggerInterface $logger = null
|
?LoggerInterface $logger = null
|
||||||
): ResponseInterface
|
): ResponseInterface {
|
||||||
{
|
|
||||||
if ($logger !== null && $logErrors === true) {
|
if ($logger !== null && $logErrors === true) {
|
||||||
$logger->error($exception->getMessage());
|
$logger->error($exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class JsonBodyParserMiddleware implements MiddlewareInterface
|
|||||||
{
|
{
|
||||||
$contentType = $request->getHeaderLine('Content-Type');
|
$contentType = $request->getHeaderLine('Content-Type');
|
||||||
|
|
||||||
if (strstr($contentType, 'application/json')) {
|
if (str_contains($contentType, 'application/json')) {
|
||||||
$contents = json_decode(file_get_contents('php://input'), true);
|
$contents = json_decode(file_get_contents('php://input'), true);
|
||||||
if (json_last_error() === JSON_ERROR_NONE) {
|
if (json_last_error() === JSON_ERROR_NONE) {
|
||||||
$request = $request->withParsedBody($contents);
|
$request = $request->withParsedBody($contents);
|
||||||
|
|||||||
@@ -28,15 +28,14 @@ class OriginAccessControlHandler implements MiddlewareInterface
|
|||||||
|
|
||||||
public function originAccessControl(Request $request, Response $response): Response
|
public function originAccessControl(Request $request, Response $response): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
$routeContext = RouteContext::fromRequest($request);
|
$routeContext = RouteContext::fromRequest($request);
|
||||||
$routingResults = $routeContext->getRoutingResults();
|
$routingResults = $routeContext->getRoutingResults();
|
||||||
$methods = $routingResults->getAllowedMethods();
|
$methods = $routingResults->getAllowedMethods();
|
||||||
$requestHeaders = $request->getHeaderLine('Access-Control-Request-Headers');
|
$requestHeaders = $request->getHeaderLine('Access-Control-Request-Headers');
|
||||||
|
|
||||||
if ($this->testRoute($request)) {
|
if ($this->testRoute($request)) {
|
||||||
// Stunden Minuten Sekunden
|
// Stunden Minuten Sekunden
|
||||||
$accessControlMaxAge = 24 * 60 * 60;
|
$accessControlMaxAge = 24 * 60 * 60;
|
||||||
$response = $response->withHeader('Access-Control-Allow-Origin', $this->buildOrigin($request));
|
$response = $response->withHeader('Access-Control-Allow-Origin', $this->buildOrigin($request));
|
||||||
$response = $response->withHeader('Access-Control-Allow-Methods', implode(',', $methods));
|
$response = $response->withHeader('Access-Control-Allow-Methods', implode(',', $methods));
|
||||||
$response = $response->withHeader('Access-Control-Allow-Headers', $requestHeaders);
|
$response = $response->withHeader('Access-Control-Allow-Headers', $requestHeaders);
|
||||||
@@ -53,6 +52,6 @@ class OriginAccessControlHandler implements MiddlewareInterface
|
|||||||
|
|
||||||
protected function buildOrigin(Request $request): string
|
protected function buildOrigin(Request $request): string
|
||||||
{
|
{
|
||||||
return $request->getHeaderLine('Origin') ?? '';
|
return $request->getHeaderLine('Origin');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,16 @@
|
|||||||
<?php /** @noinspection PhpUnusedPrivateFieldInspection */
|
<?php
|
||||||
|
/** @noinspection PhpUnusedPrivateFieldInspection */
|
||||||
|
|
||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Models;
|
namespace TorstenHettstedt\TimekeepingApi\Models;
|
||||||
|
|
||||||
use MyCLabs\Enum\Enum;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum-Klasse für die unterstützten Periode-Definitionen.
|
* Enum-Klasse für die unterstützten Periode-Definitionen.
|
||||||
* Der Wert der Periode ist ein Format-String für {@link https://secure.php.net/manual/en/datetime.format.php}.
|
* Der Wert der Periode ist ein Format-String für {@link https://secure.php.net/manual/en/datetime.format.php}.
|
||||||
*
|
|
||||||
* @extends Enum<string>
|
|
||||||
*
|
|
||||||
* @method static PeriodDesignationEnum WEEKLY()
|
|
||||||
* @method static PeriodDesignationEnum MONTHLY()
|
|
||||||
* @method static PeriodDesignationEnum YEARLY()
|
|
||||||
*/
|
*/
|
||||||
class PeriodDesignationEnum extends Enum
|
enum PeriodDesignationEnum: string
|
||||||
{
|
{
|
||||||
private const WEEKLY = 'Y#W';
|
case WEEKLY = 'Y#W';
|
||||||
private const MONTHLY = 'Y-m';
|
case MONTHLY = 'Y-m';
|
||||||
private const YEARLY = 'Y';
|
case YEARLY = 'Y';
|
||||||
}
|
}
|
||||||
@@ -10,42 +10,26 @@ use JetBrains\PhpStorm\ArrayShape;
|
|||||||
|
|
||||||
class WorkingHours implements ModelInterface
|
class WorkingHours implements ModelInterface
|
||||||
{
|
{
|
||||||
protected ?DateTime $workingDay = null;
|
protected ?DateTime $workingDay = null;
|
||||||
protected ?DateInterval $workingTime = null;
|
protected ?DateInterval $workingTime = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return DateTime|null
|
|
||||||
*/
|
|
||||||
public function getWorkingDay(): ?DateTime
|
public function getWorkingDay(): ?DateTime
|
||||||
{
|
{
|
||||||
return $this->workingDay;
|
return $this->workingDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setWorkingDay(DateTime $workingDay): static
|
||||||
* @param DateTime $workingDay
|
|
||||||
*
|
|
||||||
* @return WorkingHours
|
|
||||||
*/
|
|
||||||
public function setWorkingDay(DateTime $workingDay): WorkingHours
|
|
||||||
{
|
{
|
||||||
$this->workingDay = $workingDay;
|
$this->workingDay = $workingDay;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return DateInterval|null
|
|
||||||
*/
|
|
||||||
public function getWorkingTime(): ?DateInterval
|
public function getWorkingTime(): ?DateInterval
|
||||||
{
|
{
|
||||||
return $this->workingTime;
|
return $this->workingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setWorkingTime(DateInterval $workingTime): static
|
||||||
* @param DateInterval $workingTime
|
|
||||||
*
|
|
||||||
* @return WorkingHours
|
|
||||||
*/
|
|
||||||
public function setWorkingTime(DateInterval $workingTime): WorkingHours
|
|
||||||
{
|
{
|
||||||
$this->workingTime = $workingTime;
|
$this->workingTime = $workingTime;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -58,7 +42,7 @@ class WorkingHours implements ModelInterface
|
|||||||
public function jsonSerialize(): array
|
public function jsonSerialize(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'workingDay' => $this->getWorkingDay()->format('Y-m-d'),
|
'workingDay' => $this->getWorkingDay()->format('Y-m-d'),
|
||||||
'workingTime' => $this->getWorkingTime()->format('%H:%I:%S')
|
'workingTime' => $this->getWorkingTime()->format('%H:%I:%S')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,12 @@ use JetBrains\PhpStorm\ArrayShape;
|
|||||||
|
|
||||||
class WorkingHoursView implements ModelInterface
|
class WorkingHoursView implements ModelInterface
|
||||||
{
|
{
|
||||||
protected DateTimeInterface $period;
|
protected DateTimeInterface $period;
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
protected PeriodDesignationEnum $periodDesignation;
|
||||||
protected int $workingDays;
|
protected int $workingDays;
|
||||||
protected DateInterval $totalHours;
|
protected DateInterval $totalHours;
|
||||||
protected DateInterval $overtime;
|
protected DateInterval $overtime;
|
||||||
|
|
||||||
/**
|
|
||||||
* WorkingHoursView constructor.
|
|
||||||
*
|
|
||||||
* @param DateTimeInterface $period
|
|
||||||
* @param PeriodDesignationEnum $periodDesignation
|
|
||||||
* @param int $workingDays
|
|
||||||
* @param DateInterval $totalHours
|
|
||||||
* @param DateInterval $overtime
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DateTimeInterface $period,
|
DateTimeInterface $period,
|
||||||
PeriodDesignationEnum $periodDesignation,
|
PeriodDesignationEnum $periodDesignation,
|
||||||
@@ -39,41 +30,26 @@ class WorkingHoursView implements ModelInterface
|
|||||||
$this->overtime = $overtime;
|
$this->overtime = $overtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return DateTimeInterface
|
|
||||||
*/
|
|
||||||
public function getPeriod(): DateTimeInterface
|
public function getPeriod(): DateTimeInterface
|
||||||
{
|
{
|
||||||
return $this->period;
|
return $this->period;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return PeriodDesignationEnum
|
|
||||||
*/
|
|
||||||
public function getPeriodDesignation(): PeriodDesignationEnum
|
public function getPeriodDesignation(): PeriodDesignationEnum
|
||||||
{
|
{
|
||||||
return $this->periodDesignation;
|
return $this->periodDesignation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getWorkingDays(): int
|
public function getWorkingDays(): int
|
||||||
{
|
{
|
||||||
return $this->workingDays;
|
return $this->workingDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return DateInterval
|
|
||||||
*/
|
|
||||||
public function getTotalHours(): DateInterval
|
public function getTotalHours(): DateInterval
|
||||||
{
|
{
|
||||||
return $this->totalHours;
|
return $this->totalHours;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return DateInterval
|
|
||||||
*/
|
|
||||||
public function getOvertime(): DateInterval
|
public function getOvertime(): DateInterval
|
||||||
{
|
{
|
||||||
return $this->overtime;
|
return $this->overtime;
|
||||||
@@ -84,17 +60,18 @@ class WorkingHoursView implements ModelInterface
|
|||||||
*
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
#[ArrayShape(['period' => "string",
|
#[ArrayShape([
|
||||||
'periodDesignation' => "string",
|
'period' => "string",
|
||||||
'totalHours' => "string",
|
'periodDesignation' => "string",
|
||||||
'workingDays' => "int",
|
'totalHours' => "string",
|
||||||
'overtime' => "string"
|
'workingDays' => "int",
|
||||||
|
'overtime' => "string"
|
||||||
])] public function jsonSerialize(): array
|
])] public function jsonSerialize(): array
|
||||||
{
|
{
|
||||||
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
|
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
|
||||||
return [
|
return [
|
||||||
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()),
|
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->value),
|
||||||
'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()),
|
'periodDesignation' => strtolower($this->getPeriodDesignation()->name),
|
||||||
'workingDays' => $this->getWorkingDays(),
|
'workingDays' => $this->getWorkingDays(),
|
||||||
'totalHours' => $this->getTotalHours()->format('%H:%I:%S'),
|
'totalHours' => $this->getTotalHours()->format('%H:%I:%S'),
|
||||||
'overtime' => $this->getOvertime()->format($formatOvertime)
|
'overtime' => $this->getOvertime()->format($formatOvertime)
|
||||||
|
|||||||
@@ -18,9 +18,8 @@ abstract class AbstractWorkingHoursViewRepository implements RepositoryReaderInt
|
|||||||
{
|
{
|
||||||
|
|
||||||
protected const SQL_SELECT = '';
|
protected const SQL_SELECT = '';
|
||||||
protected const SQL_WHERE = '';
|
protected const SQL_WHERE = '';
|
||||||
|
|
||||||
protected PDO $database;
|
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
protected PeriodDesignationEnum $periodDesignation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,9 +27,8 @@ abstract class AbstractWorkingHoursViewRepository implements RepositoryReaderInt
|
|||||||
*
|
*
|
||||||
* @param PDO $database
|
* @param PDO $database
|
||||||
*/
|
*/
|
||||||
public function __construct(PDO $database)
|
public function __construct(protected PDO $database)
|
||||||
{
|
{
|
||||||
$this->database = $database;
|
|
||||||
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ abstract class AbstractWorkingHoursViewRepository implements RepositoryReaderInt
|
|||||||
$model = new WorkingHoursView(
|
$model = new WorkingHoursView(
|
||||||
$this->buildDateFromPeriod($row['period']),
|
$this->buildDateFromPeriod($row['period']),
|
||||||
$this->periodDesignation,
|
$this->periodDesignation,
|
||||||
(int) $row['workingDays'],
|
(int)$row['workingDays'],
|
||||||
$this->buildDateInterval($row['totalHours']),
|
$this->buildDateInterval($row['totalHours']),
|
||||||
$this->buildDateInterval($row['overtime'])
|
$this->buildDateInterval($row['overtime'])
|
||||||
);
|
);
|
||||||
@@ -82,7 +80,7 @@ abstract class AbstractWorkingHoursViewRepository implements RepositoryReaderInt
|
|||||||
return new WorkingHoursView(
|
return new WorkingHoursView(
|
||||||
$this->buildDateFromPeriod($row['period']),
|
$this->buildDateFromPeriod($row['period']),
|
||||||
$this->periodDesignation,
|
$this->periodDesignation,
|
||||||
(int) $row['workingDays'],
|
(int)$row['workingDays'],
|
||||||
$this->buildDateInterval($row['totalHours']),
|
$this->buildDateInterval($row['totalHours']),
|
||||||
$this->buildDateInterval($row['overtime'])
|
$this->buildDateInterval($row['overtime'])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T of \TorstenHettstedt\TimekeepingApi\Models\ModelInterface
|
* @template T of ModelInterface
|
||||||
*/
|
*/
|
||||||
interface RepositoryReaderInterface
|
interface RepositoryReaderInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T of \TorstenHettstedt\TimekeepingApi\Models\ModelInterface
|
* @template T of ModelInterface
|
||||||
*/
|
*/
|
||||||
interface RepositoryWriterInterface
|
interface RepositoryWriterInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,15 +20,12 @@ class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewReposito
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Monat"
|
from "Arbeitszeiten - Monat"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Monat" = ?';
|
protected const SQL_WHERE = ' where "Monat" = ?';
|
||||||
|
|
||||||
protected PDO $database;
|
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
parent::__construct($database);
|
parent::__construct($database);
|
||||||
$this->periodDesignation = PeriodDesignationEnum::MONTHLY();
|
$this->periodDesignation = PeriodDesignationEnum::MONTHLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildDateFromPeriod(string $period): DateTimeInterface
|
protected function buildDateFromPeriod(string $period): DateTimeInterface
|
||||||
|
|||||||
@@ -21,16 +21,8 @@ use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
|||||||
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
|
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
protected PDO $database;
|
public function __construct(protected PDO $database)
|
||||||
|
|
||||||
/**
|
|
||||||
* WorkingHoursRepository constructor.
|
|
||||||
*
|
|
||||||
* @param PDO $database
|
|
||||||
*/
|
|
||||||
public function __construct(PDO $database)
|
|
||||||
{
|
{
|
||||||
$this->database = $database;
|
|
||||||
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +98,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
|||||||
if (is_string($end)) {
|
if (is_string($end)) {
|
||||||
$stmt->bindParam(':end', $end);
|
$stmt->bindParam(':end', $end);
|
||||||
}
|
}
|
||||||
return $stmt ?? null;
|
return $stmt ?: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +113,9 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
|||||||
*/
|
*/
|
||||||
public function findByKey(mixed $primary_key): WorkingHours
|
public function findByKey(mixed $primary_key): WorkingHours
|
||||||
{
|
{
|
||||||
$stmt = $this->database->prepare('select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" where "Datum" = ?');
|
$stmt = $this->database->prepare(
|
||||||
|
'select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" where "Datum" = ?'
|
||||||
|
);
|
||||||
$stmt->bindParam(1, $primary_key);
|
$stmt->bindParam(1, $primary_key);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetch();
|
$row = $stmt->fetch();
|
||||||
@@ -155,7 +149,9 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
|||||||
throw new RepositoryRecordAlreadyExistException();
|
throw new RepositoryRecordAlreadyExistException();
|
||||||
} /** @noinspection PhpUnusedLocalVariableInspection */
|
} /** @noinspection PhpUnusedLocalVariableInspection */
|
||||||
catch (RepositoryRecordNotFoundException $exception) {
|
catch (RepositoryRecordNotFoundException $exception) {
|
||||||
$stmt = $this->database->prepare('insert into public."Arbeitszeiten" ("Datum", "Arbeitszeit") values (?, ?) on conflict do nothing');
|
$stmt = $this->database->prepare(
|
||||||
|
'insert into public."Arbeitszeiten" ("Datum", "Arbeitszeit") values (?, ?) on conflict do nothing'
|
||||||
|
);
|
||||||
$stmt->bindParam(1, $workingDay);
|
$stmt->bindParam(1, $workingDay);
|
||||||
$stmt->bindParam(2, $workingTime);
|
$stmt->bindParam(2, $workingTime);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|||||||
@@ -19,15 +19,12 @@ class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepositor
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Woche"
|
from "Arbeitszeiten - Woche"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Woche" = ?';
|
protected const SQL_WHERE = ' where "Woche" = ?';
|
||||||
|
|
||||||
protected PDO $database;
|
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
parent::__construct($database);
|
parent::__construct($database);
|
||||||
$this->periodDesignation = PeriodDesignationEnum::WEEKLY();
|
$this->periodDesignation = PeriodDesignationEnum::WEEKLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildDateFromPeriod(string $period): DateTimeInterface
|
protected function buildDateFromPeriod(string $period): DateTimeInterface
|
||||||
|
|||||||
@@ -19,15 +19,12 @@ class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepositor
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Jahr"
|
from "Arbeitszeiten - Jahr"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Jahr" = ?';
|
protected const SQL_WHERE = ' where "Jahr" = ?';
|
||||||
|
|
||||||
protected PDO $database;
|
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
parent::__construct($database);
|
parent::__construct($database);
|
||||||
$this->periodDesignation = PeriodDesignationEnum::YEARLY();
|
$this->periodDesignation = PeriodDesignationEnum::YEARLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+64
-64
@@ -13,10 +13,10 @@ SET xmloption = content;
|
|||||||
SET client_min_messages = warning;
|
SET client_min_messages = warning;
|
||||||
SET row_security = off;
|
SET row_security = off;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS public."Arbeitszeiten";
|
|
||||||
DROP VIEW IF EXISTS public."Arbeitszeiten - Woche";
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Woche";
|
||||||
DROP VIEW IF EXISTS public."Arbeitszeiten - Monat";
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Monat";
|
||||||
DROP VIEW IF EXISTS public."Arbeitszeiten - Jahr";
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Jahr";
|
||||||
|
DROP TABLE IF EXISTS public."Arbeitszeiten";
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: Arbeitszeiten; Type: TABLE; Schema: public; Owner: torsten
|
-- Name: Arbeitszeiten; Type: TABLE; Schema: public; Owner: torsten
|
||||||
@@ -83,66 +83,66 @@ ALTER TABLE public."Arbeitszeiten - Woche" OWNER TO bruce;
|
|||||||
-- Data for Name: Arbeitszeiten; Type: TABLE DATA; Schema: public; Owner: torsten
|
-- Data for Name: Arbeitszeiten; Type: TABLE DATA; Schema: public; Owner: torsten
|
||||||
--
|
--
|
||||||
|
|
||||||
COPY public."Arbeitszeiten" ("Datum", "Arbeitszeit") FROM stdin;
|
INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit") VALUES
|
||||||
2020-01-07 08:06:00
|
('2020-01-07','08:06:00'),
|
||||||
2020-01-08 08:16:00
|
('2020-01-08','08:16:00'),
|
||||||
2020-01-09 07:49:00
|
('2020-01-09','07:49:00'),
|
||||||
2020-01-10 07:30:00
|
('2020-01-10','07:30:00'),
|
||||||
2020-01-13 08:06:00
|
('2020-01-13','08:06:00'),
|
||||||
2020-01-14 08:04:00
|
('2020-01-14','08:04:00'),
|
||||||
2020-01-15 08:20:00
|
('2020-01-15','08:20:00'),
|
||||||
2020-01-16 07:13:00
|
('2020-01-16','07:13:00'),
|
||||||
2020-01-17 07:57:00
|
('2020-01-17','07:57:00'),
|
||||||
2020-01-20 07:53:00
|
('2020-01-20','07:53:00'),
|
||||||
2020-01-21 07:49:00
|
('2020-01-21','07:49:00'),
|
||||||
2020-01-22 07:56:00
|
('2020-01-22','07:56:00'),
|
||||||
2020-01-23 07:55:00
|
('2020-01-23','07:55:00'),
|
||||||
2020-01-24 07:08:00
|
('2020-01-24','07:08:00'),
|
||||||
2020-01-27 08:23:00
|
('2020-01-27','08:23:00'),
|
||||||
2020-01-28 07:20:00
|
('2020-01-28','07:20:00'),
|
||||||
2020-01-29 08:13:00
|
('2020-01-29','08:13:00'),
|
||||||
2020-01-30 08:43:00
|
('2020-01-30','08:43:00'),
|
||||||
2020-01-31 07:21:00
|
('2020-01-31','07:21:00'),
|
||||||
2020-02-03 07:56:00
|
('2020-02-03','07:56:00'),
|
||||||
2020-02-04 08:05:00
|
('2020-02-04','08:05:00'),
|
||||||
2020-02-05 07:58:00
|
('2020-02-05','07:58:00'),
|
||||||
2020-02-06 08:01:00
|
('2020-02-06','08:01:00'),
|
||||||
2020-02-07 07:59:00
|
('2020-02-07','07:59:00'),
|
||||||
2020-02-10 07:50:00
|
('2020-02-10','07:50:00'),
|
||||||
2020-02-11 08:01:00
|
('2020-02-11','08:01:00'),
|
||||||
2020-02-12 08:14:00
|
('2020-02-12','08:14:00'),
|
||||||
2020-02-13 08:12:00
|
('2020-02-13','08:12:00'),
|
||||||
2020-02-14 07:51:00
|
('2020-02-14','07:51:00'),
|
||||||
2020-02-17 07:59:00
|
('2020-02-17','07:59:00'),
|
||||||
2020-02-18 08:05:00
|
('2020-02-18','08:05:00'),
|
||||||
2020-02-19 07:34:00
|
('2020-02-19','07:34:00'),
|
||||||
2020-02-20 07:33:00
|
('2020-02-20','07:33:00'),
|
||||||
2020-02-21 07:56:00
|
('2020-02-21','07:56:00'),
|
||||||
2020-02-24 08:02:00
|
('2020-02-24','08:02:00'),
|
||||||
2020-02-25 08:13:00
|
('2020-02-25','08:13:00'),
|
||||||
2020-02-26 08:42:00
|
('2020-02-26','08:42:00'),
|
||||||
2020-02-27 07:49:00
|
('2020-02-27','07:49:00'),
|
||||||
2020-02-28 08:16:00
|
('2020-02-28','08:16:00'),
|
||||||
2020-03-02 08:22:00
|
('2020-03-02','08:22:00'),
|
||||||
2020-03-03 08:20:00
|
('2020-03-03','08:20:00'),
|
||||||
2020-03-04 08:12:00
|
('2020-03-04','08:12:00'),
|
||||||
2020-03-05 08:32:00
|
('2020-03-05','08:32:00'),
|
||||||
2020-03-06 04:41:00
|
('2020-03-06','04:41:00'),
|
||||||
2020-03-09 07:05:00
|
('2020-03-09','07:05:00'),
|
||||||
2020-03-10 07:34:00
|
('2020-03-10','07:34:00'),
|
||||||
2020-03-11 07:39:00
|
('2020-03-11','07:39:00'),
|
||||||
2020-03-12 07:50:00
|
('2020-03-12','07:50:00'),
|
||||||
2020-03-13 08:26:00
|
('2020-03-13','08:26:00'),
|
||||||
2020-03-16 07:51:00
|
('2020-03-16','07:51:00'),
|
||||||
2020-03-17 07:50:00
|
('2020-03-17','07:50:00'),
|
||||||
2020-03-18 07:19:00
|
('2020-03-18','07:19:00'),
|
||||||
2020-03-19 07:55:00
|
('2020-03-19','07:55:00'),
|
||||||
2020-03-20 05:43:00
|
('2020-03-20','05:43:00'),
|
||||||
2020-03-23 08:05:00
|
('2020-03-23','08:05:00'),
|
||||||
2020-03-24 08:21:00
|
('2020-03-24','08:21:00'),
|
||||||
2020-03-25 08:10:00
|
('2020-03-25','08:10:00'),
|
||||||
2020-03-26 10:31:00
|
('2020-03-26','10:31:00'),
|
||||||
2020-03-27 04:55:00
|
('2020-03-27','04:55:00'),
|
||||||
2020-03-30 08:21:00
|
('2020-03-30','08:21:00'),
|
||||||
2020-03-31 08:01:00
|
('2020-03-31','08:01:00')
|
||||||
\.
|
;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
||||||
|
|
||||||
|
use Codeception\Test\Unit;
|
||||||
|
use Exception;
|
||||||
|
use PDO;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use Slim\Psr7\Request;
|
||||||
|
use Slim\Psr7\Response;
|
||||||
|
|
||||||
|
class AbstractControllerTest extends Unit
|
||||||
|
{
|
||||||
|
|
||||||
|
protected const FICTIONAL_STATUS_CODE = 666;
|
||||||
|
|
||||||
|
protected ContainerInterface $container;
|
||||||
|
protected Request $request;
|
||||||
|
protected Response|MockObject $response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
* @throws \PHPUnit\Framework\MockObject\Exception
|
||||||
|
*/
|
||||||
|
protected function _before(): void
|
||||||
|
{
|
||||||
|
parent::_before();
|
||||||
|
/** @noinspection SpellCheckingInspection */
|
||||||
|
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||||
|
'has' => true,
|
||||||
|
'get' => new PDO(
|
||||||
|
'pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
$this->response = $this->createMock(Response::class);
|
||||||
|
$this->response->expects($this->any())->method('getStatusCode')->willReturn(self::FICTIONAL_STATUS_CODE);
|
||||||
|
$this->response->expects($this->any())->method('getBody')->willReturn(
|
||||||
|
$this->makeEmpty(StreamInterface::class, [
|
||||||
|
'write' => function (mixed $data) {
|
||||||
|
$this->assertIsString($data);
|
||||||
|
$this->assertJson($data);
|
||||||
|
return strlen($data);
|
||||||
|
},
|
||||||
|
'getContents' => 'abc',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
$this->response->expects($this->any())->method('withHeader')->willReturn($this->response);
|
||||||
|
$this->response->expects($this->any())->method('withStatus')->willReturn($this->response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
||||||
|
|
||||||
use Codeception\Example;
|
use Codeception\Attribute\DataProvider;
|
||||||
use Codeception\Test\Unit;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PDO;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Slim\Exception\HttpBadRequestException;
|
use Slim\Exception\HttpBadRequestException;
|
||||||
use Slim\Exception\HttpInternalServerErrorException;
|
|
||||||
use Slim\Exception\HttpNotFoundException;
|
use Slim\Exception\HttpNotFoundException;
|
||||||
use Slim\Psr7\Request;
|
use Slim\Psr7\Request;
|
||||||
use Slim\Psr7\Response;
|
use Slim\Psr7\Response;
|
||||||
@@ -17,50 +16,38 @@ use TorstenHettstedt\TimekeepingApi\Controller\HttpConflictRequestException;
|
|||||||
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursController;
|
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursController;
|
||||||
|
|
||||||
class WorkingHoursControllerTest extends Unit
|
class WorkingHoursControllerTest extends AbstractControllerTest
|
||||||
{
|
{
|
||||||
|
|
||||||
const EXISTING_DATE = '2020-01-28';
|
protected const FICTIONAL_STATUS_CODE = 666;
|
||||||
const EXISTING_INTERVAL = '07:20:00';
|
public const EXISTING_DATE = '2020-01-28';
|
||||||
const NEW_DATE = '2020-04-01';
|
public const EXISTING_INTERVAL = '07:20:00';
|
||||||
const NEW_INTERVAL = '07:59:00';
|
public const NEW_DATE = '2020-04-01';
|
||||||
|
public const NEW_INTERVAL = '07:59:00';
|
||||||
|
|
||||||
protected ContainerInterface $container;
|
protected ContainerInterface $container;
|
||||||
protected Request $request;
|
protected Request $request;
|
||||||
protected Response $response;
|
protected Response|MockObject $response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @throws \PHPUnit\Framework\MockObject\Exception
|
||||||
*/
|
*/
|
||||||
protected function _before(): void
|
protected function _before(): void
|
||||||
{
|
{
|
||||||
parent::_before();
|
parent::_before();
|
||||||
/** @noinspection SpellCheckingInspection */
|
|
||||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
|
||||||
'has' => true,
|
|
||||||
'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'),
|
|
||||||
]);
|
|
||||||
$this->request = $this->makeEmpty(Request::class, [
|
$this->request = $this->makeEmpty(Request::class, [
|
||||||
'getParsedBody' => [
|
'getParsedBody' => [
|
||||||
'workingDay' => self::EXISTING_DATE,
|
'workingDay' => self::EXISTING_DATE,
|
||||||
'workingTime' => self::EXISTING_INTERVAL,
|
'workingTime' => self::EXISTING_INTERVAL,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$this->response = $this->makeEmpty(Response::class, [
|
|
||||||
'getBody' => $this->makeEmpty(StreamInterface::class, [
|
|
||||||
'write' => function (mixed $data) {
|
|
||||||
$this->assertIsString($data);
|
|
||||||
$this->assertJson($data);
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
'withHeader' => $this->makeEmpty(Response::class, [
|
|
||||||
'withStatus' => $this->makeEmpty(Response::class),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testConstructWithNonDatabase(): void
|
public function testConstructWithNonDatabase(): void
|
||||||
@@ -103,12 +90,12 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
/**
|
/**
|
||||||
* @param array<string, string> $queryParams
|
* @param array<string, string> $queryParams
|
||||||
*
|
*
|
||||||
* @dataProvider valideFilterDataProvider
|
* @throws ContainerExceptionInterface
|
||||||
*
|
|
||||||
* @throws HttpInternalServerErrorException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('valideFilterDataProvider')]
|
||||||
public function testBrowseWithValideParameter(array $queryParams): void
|
public function testBrowseWithValideParameter(array $queryParams): void
|
||||||
{
|
{
|
||||||
$this->request = $this->makeEmpty(Request::class, [
|
$this->request = $this->makeEmpty(Request::class, [
|
||||||
@@ -116,7 +103,8 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
]);
|
]);
|
||||||
$controller = new WorkingHoursController($this->container);
|
$controller = new WorkingHoursController($this->container);
|
||||||
$response = $controller->browse($this->request, $this->response, []);
|
$response = $controller->browse($this->request, $this->response, []);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,12 +234,12 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
/**
|
/**
|
||||||
* @param array<string, string> $queryParams
|
* @param array<string, string> $queryParams
|
||||||
*
|
*
|
||||||
* @dataProvider invalideFilterDataProvider
|
* @throws ContainerExceptionInterface
|
||||||
*
|
|
||||||
* @throws HttpInternalServerErrorException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('invalideFilterDataProvider')]
|
||||||
public function testBrowseWithInvalideParameter(array $queryParams): void
|
public function testBrowseWithInvalideParameter(array $queryParams): void
|
||||||
{
|
{
|
||||||
$this->request = $this->makeEmpty(Request::class, [
|
$this->request = $this->makeEmpty(Request::class, [
|
||||||
@@ -263,9 +251,10 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
* @throws HttpBadRequestException
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws HttpNotFoundException
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testUpdateExistRecord(): void
|
public function testUpdateExistRecord(): void
|
||||||
{
|
{
|
||||||
@@ -273,13 +262,15 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
$response = $controller->update($this->request, $this->response, [
|
$response = $controller->update($this->request, $this->response, [
|
||||||
'id' => self::EXISTING_DATE,
|
'id' => self::EXISTING_DATE,
|
||||||
]);
|
]);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
* @throws HttpBadRequestException
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws HttpNotFoundException
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testUpdateNotExistRecord(): void
|
public function testUpdateNotExistRecord(): void
|
||||||
{
|
{
|
||||||
@@ -311,14 +302,12 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
* @param string $date
|
* @param string $date
|
||||||
* @param string $time
|
* @param string $time
|
||||||
*
|
*
|
||||||
* @dataProvider invalidCreatDataProvider
|
* @throws ContainerExceptionInterface
|
||||||
*
|
|
||||||
* @throws HttpBadRequestException
|
|
||||||
* @throws HttpConflictRequestException
|
|
||||||
* @throws HttpInternalServerErrorException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('invalidCreatDataProvider')]
|
||||||
public function testCreatInvalidData(string $date, string $time): void
|
public function testCreatInvalidData(string $date, string $time): void
|
||||||
{
|
{
|
||||||
$this->request = $this->makeEmpty(Request::class, [
|
$this->request = $this->makeEmpty(Request::class, [
|
||||||
@@ -333,10 +322,9 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws HttpBadRequestException
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
* @throws HttpInternalServerErrorException
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws HttpConflictRequestException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testCreatNewRecord(): void
|
public function testCreatNewRecord(): void
|
||||||
@@ -349,14 +337,14 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
]);
|
]);
|
||||||
$controller = new WorkingHoursController($this->container);
|
$controller = new WorkingHoursController($this->container);
|
||||||
$response = $controller->creat($this->request, $this->response, []);
|
$response = $controller->creat($this->request, $this->response, []);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws HttpBadRequestException
|
* @throws ContainerExceptionInterface
|
||||||
* @throws HttpConflictRequestException
|
|
||||||
* @throws HttpInternalServerErrorException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testCreatExistRecord(): void
|
public function testCreatExistRecord(): void
|
||||||
@@ -373,9 +361,10 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws HttpInternalServerErrorException
|
* @throws ContainerExceptionInterface
|
||||||
* @throws HttpNotFoundException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testReadExistRecord(): void
|
public function testReadExistRecord(): void
|
||||||
{
|
{
|
||||||
@@ -383,13 +372,15 @@ class WorkingHoursControllerTest extends Unit
|
|||||||
$response = $controller->read($this->request, $this->response, [
|
$response = $controller->read($this->request, $this->response, [
|
||||||
'id' => self::EXISTING_DATE,
|
'id' => self::EXISTING_DATE,
|
||||||
]);
|
]);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws HttpInternalServerErrorException
|
* @throws ContainerExceptionInterface
|
||||||
* @throws HttpNotFoundException
|
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testReadNotExistRecord(): void
|
public function testReadNotExistRecord(): void
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,49 +2,30 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
||||||
|
|
||||||
use Codeception\Test\Unit;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PDO;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Slim\Psr7\Request;
|
use Slim\Psr7\Request;
|
||||||
use Slim\Psr7\Response;
|
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursViewController;
|
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursViewController;
|
||||||
|
|
||||||
class WorkingHoursViewControllerTest extends Unit
|
class WorkingHoursViewControllerTest extends AbstractControllerTest
|
||||||
{
|
{
|
||||||
protected ContainerInterface $container;
|
|
||||||
protected Request $request;
|
|
||||||
protected Response $response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @throws \PHPUnit\Framework\MockObject\Exception
|
||||||
*/
|
*/
|
||||||
protected function _before(): void
|
protected function _before(): void
|
||||||
{
|
{
|
||||||
parent::_before();
|
parent::_before();
|
||||||
/** @noinspection SpellCheckingInspection */
|
$this->request = $this->makeEmpty(Request::class);
|
||||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
|
||||||
'has' => true,
|
|
||||||
'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass')
|
|
||||||
]);
|
|
||||||
$this->request = $this->makeEmpty(Request::class, []);
|
|
||||||
$this->response = $this->makeEmpty(Response::class, [
|
|
||||||
'getBody' => $this->makeEmpty(StreamInterface::class, [
|
|
||||||
'write' => function (mixed $data) {
|
|
||||||
$this->assertIsString($data);
|
|
||||||
$this->assertJson($data);
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
'withHeader' => $this->makeEmpty(Response::class, [
|
|
||||||
'withStatus' => $this->makeEmpty(Response::class),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testConstructWithNonDatabase(): void
|
public function testConstructWithNonDatabase(): void
|
||||||
@@ -57,32 +38,44 @@ class WorkingHoursViewControllerTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testBrowseMonthly(): void
|
public function testBrowseMonthly(): void
|
||||||
{
|
{
|
||||||
$controller = new WorkingHoursViewController($this->container);
|
$controller = new WorkingHoursViewController($this->container);
|
||||||
$response = $controller->browseMonthly($this->request, $this->response, []);
|
$response = $controller->browseMonthly($this->request, $this->response, []);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testBrowseYearly(): void
|
public function testBrowseYearly(): void
|
||||||
{
|
{
|
||||||
$controller = new WorkingHoursViewController($this->container);
|
$controller = new WorkingHoursViewController($this->container);
|
||||||
$response = $controller->browseYearly($this->request, $this->response, []);
|
$response = $controller->browseYearly($this->request, $this->response, []);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws NotDatabasesException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testBrowseWeekly(): void
|
public function testBrowseWeekly(): void
|
||||||
{
|
{
|
||||||
$controller = new WorkingHoursViewController($this->container);
|
$controller = new WorkingHoursViewController($this->container);
|
||||||
$response = $controller->browseWeekly($this->request, $this->response, []);
|
$response = $controller->browseWeekly($this->request, $this->response, []);
|
||||||
$this->assertInstanceOf(Response::class, $response);
|
$this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode());
|
||||||
|
$this->assertNotEmpty($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Middleware;
|
|||||||
use Codeception\Stub\Expected;
|
use Codeception\Stub\Expected;
|
||||||
use Codeception\Test\Unit;
|
use Codeception\Test\Unit;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\ResponseFactoryInterface;
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -20,6 +21,7 @@ use TorstenHettstedt\TimekeepingApi\Middleware\ErrorHandler;
|
|||||||
class ErrorHandlerTest extends Unit
|
class ErrorHandlerTest extends Unit
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var App<ContainerInterface> */
|
||||||
protected App $app;
|
protected App $app;
|
||||||
protected ServerRequestInterface $request;
|
protected ServerRequestInterface $request;
|
||||||
protected Exception $exception;
|
protected Exception $exception;
|
||||||
@@ -38,6 +40,7 @@ class ErrorHandlerTest extends Unit
|
|||||||
'write' => function (mixed $data) {
|
'write' => function (mixed $data) {
|
||||||
$this->assertIsString($data);
|
$this->assertIsString($data);
|
||||||
$this->assertJson($data);
|
$this->assertJson($data);
|
||||||
|
return strlen($data);
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
@@ -87,11 +90,10 @@ class ErrorHandlerTest extends Unit
|
|||||||
'file' => '/path(to/file',
|
'file' => '/path(to/file',
|
||||||
'getTitle' => Expected::once('The Title'),
|
'getTitle' => Expected::once('The Title'),
|
||||||
]);
|
]);
|
||||||
$this->logger = $this->makeEmpty(LoggerInterface::class, []);
|
$this->logger = $this->makeEmpty(LoggerInterface::class);
|
||||||
|
|
||||||
$middleWare = new ErrorHandler($this->app);
|
$middleWare = new ErrorHandler($this->app);
|
||||||
$middleWare($this->request, $this->exception, true, true, true, $this->logger);
|
$middleWare($this->request, $this->exception, true, true, true, $this->logger);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +106,7 @@ class ErrorHandlerTest extends Unit
|
|||||||
'code' => 400,
|
'code' => 400,
|
||||||
'file' => '/path(to/file',
|
'file' => '/path(to/file',
|
||||||
]);
|
]);
|
||||||
$this->logger = $this->makeEmpty(LoggerInterface::class, []);
|
$this->logger = $this->makeEmpty(LoggerInterface::class);
|
||||||
|
|
||||||
$middleWare = new ErrorHandler($this->app);
|
$middleWare = new ErrorHandler($this->app);
|
||||||
$middleWare($this->request, $this->exception, true, true, true, $this->logger);
|
$middleWare($this->request, $this->exception, true, true, true, $this->logger);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
||||||
|
|
||||||
|
use Codeception\Attribute\DataProvider;
|
||||||
use Codeception\Test\Unit;
|
use Codeception\Test\Unit;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
@@ -22,7 +23,7 @@ class WorkingHoursTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array<array<DateTime|DateInterval|array<string,string>>>
|
||||||
*/
|
*/
|
||||||
public function workingHoursProvider(): array
|
public function workingHoursProvider(): array
|
||||||
{
|
{
|
||||||
@@ -49,17 +50,13 @@ class WorkingHoursTest extends Unit
|
|||||||
/**
|
/**
|
||||||
* @param DateTime $date
|
* @param DateTime $date
|
||||||
* @param DateInterval $interval
|
* @param DateInterval $interval
|
||||||
* @param array<string, string> $should_json
|
* @param array<string, string> $shouldJson
|
||||||
*
|
|
||||||
* @dataProvider workingHoursProvider
|
|
||||||
*/
|
*/
|
||||||
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 = new WorkingHours();
|
||||||
$obj
|
$obj->setWorkingDay($date)->setWorkingTime($interval);
|
||||||
->setWorkingDay($date)
|
|
||||||
->setWorkingTime($interval);
|
|
||||||
|
|
||||||
$this->assertNotNull($obj->getWorkingDay());
|
$this->assertNotNull($obj->getWorkingDay());
|
||||||
$this->assertInstanceOf(DateTime::class, $obj->getWorkingDay());
|
$this->assertInstanceOf(DateTime::class, $obj->getWorkingDay());
|
||||||
@@ -70,7 +67,6 @@ class WorkingHoursTest extends Unit
|
|||||||
$this->assertEquals($interval, $obj->getWorkingTime());
|
$this->assertEquals($interval, $obj->getWorkingTime());
|
||||||
|
|
||||||
$json = $obj->jsonSerialize();
|
$json = $obj->jsonSerialize();
|
||||||
$this->assertIsArray($json);
|
$this->assertEquals($shouldJson, $json);
|
||||||
$this->assertEquals($should_json, $json);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
|
||||||
|
|
||||||
|
use Codeception\Attribute\DataProvider;
|
||||||
use Codeception\Test\Unit;
|
use Codeception\Test\Unit;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
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
|
public function workingHoursProvider(): array
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,11 @@ class WorkingHoursViewTest extends Unit
|
|||||||
$absence_time->invert = 1;
|
$absence_time->invert = 1;
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
$date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $overtime,
|
$date,
|
||||||
|
PeriodDesignationEnum::WEEKLY,
|
||||||
|
$work_days,
|
||||||
|
$total_hours,
|
||||||
|
$overtime,
|
||||||
[
|
[
|
||||||
'period' => '2020#49',
|
'period' => '2020#49',
|
||||||
'periodDesignation' => 'weekly',
|
'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',
|
'period' => '2020#49',
|
||||||
'periodDesignation' => 'weekly',
|
'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',
|
'period' => '2020-11',
|
||||||
'periodDesignation' => 'monthly',
|
'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',
|
'period' => '2020-11',
|
||||||
'periodDesignation' => 'monthly',
|
'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',
|
'period' => '2020',
|
||||||
'periodDesignation' => 'yearly',
|
'periodDesignation' => 'yearly',
|
||||||
'workingDays' => 15,
|
'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',
|
'period' => '2020',
|
||||||
'periodDesignation' => 'yearly',
|
'periodDesignation' => 'yearly',
|
||||||
'workingDays' => 15,
|
'workingDays' => 15,
|
||||||
@@ -86,50 +113,40 @@ class WorkingHoursViewTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DateTimeInterface $period
|
* @param DateTimeInterface $period
|
||||||
* @param PeriodDesignationEnum $periodDesignation
|
* @param PeriodDesignationEnum $periodDesignation
|
||||||
* @param int $workingDays
|
* @param int $workingDays
|
||||||
* @param DateInterval $totalHours
|
* @param DateInterval $totalHours
|
||||||
* @param DateInterval $overtime
|
* @param DateInterval $overtime
|
||||||
* @param array<string, string> $should_json
|
* @param array<string, string> $shouldJson
|
||||||
*
|
|
||||||
* @dataProvider workingHoursProvider
|
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('workingHoursProvider')]
|
||||||
public function testWorkingHoursViewWithContent(
|
public function testWorkingHoursViewWithContent(
|
||||||
DateTimeInterface $period,
|
DateTimeInterface $period,
|
||||||
PeriodDesignationEnum $periodDesignation,
|
PeriodDesignationEnum $periodDesignation,
|
||||||
int $workingDays,
|
int $workingDays,
|
||||||
DateInterval $totalHours,
|
DateInterval $totalHours,
|
||||||
DateInterval $overtime,
|
DateInterval $overtime,
|
||||||
array $should_json
|
array $shouldJson
|
||||||
): void
|
): void {
|
||||||
{
|
|
||||||
|
|
||||||
$obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $overtime);
|
$obj = new WorkingHoursView($period, $periodDesignation, $workingDays, $totalHours, $overtime);
|
||||||
|
|
||||||
$this->assertNotNull($obj->getPeriod());
|
|
||||||
$this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod());
|
$this->assertInstanceOf(DateTimeInterface::class, $obj->getPeriod());
|
||||||
$this->assertEquals($period, $obj->getPeriod());
|
$this->assertEquals($period, $obj->getPeriod());
|
||||||
|
|
||||||
$this->assertNotNull($obj->getPeriodDesignation());
|
|
||||||
$this->assertInstanceOf(PeriodDesignationEnum::class, $obj->getPeriodDesignation());
|
$this->assertInstanceOf(PeriodDesignationEnum::class, $obj->getPeriodDesignation());
|
||||||
$this->assertEquals($periodDesignation, $obj->getPeriodDesignation());
|
$this->assertEquals($periodDesignation, $obj->getPeriodDesignation());
|
||||||
|
|
||||||
$this->assertNotNull($obj->getWorkingDays());
|
|
||||||
$this->assertIsInt($obj->getWorkingDays());
|
|
||||||
$this->assertEquals($workingDays, $obj->getWorkingDays());
|
$this->assertEquals($workingDays, $obj->getWorkingDays());
|
||||||
|
|
||||||
$this->assertNotNull($obj->getTotalHours());
|
|
||||||
$this->assertInstanceOf(DateInterval::class, $obj->getTotalHours());
|
$this->assertInstanceOf(DateInterval::class, $obj->getTotalHours());
|
||||||
$this->assertEquals($totalHours, $obj->getTotalHours());
|
$this->assertEquals($totalHours, $obj->getTotalHours());
|
||||||
|
|
||||||
$this->assertNotNull($obj->getOvertime());
|
|
||||||
$this->assertInstanceOf(DateInterval::class, $obj->getOvertime());
|
$this->assertInstanceOf(DateInterval::class, $obj->getOvertime());
|
||||||
$this->assertEquals($overtime, $obj->getOvertime());
|
$this->assertEquals($overtime, $obj->getOvertime());
|
||||||
|
|
||||||
|
|
||||||
$json = $obj->jsonSerialize();
|
$json = $obj->jsonSerialize();
|
||||||
$this->assertIsArray($json);
|
$this->assertEquals($shouldJson, $json);
|
||||||
$this->assertEquals($should_json, $json);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||||
|
|
||||||
use Codeception\Example;
|
use Codeception\Attribute\DataProvider;
|
||||||
use Codeception\Test\Unit;
|
use Codeception\Test\Unit;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
@@ -18,18 +18,20 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursRepository;
|
|||||||
|
|
||||||
class WorkingHoursRepositoryTest extends Unit
|
class WorkingHoursRepositoryTest extends Unit
|
||||||
{
|
{
|
||||||
const EXISTING_DATE = '2020-01-28';
|
public const EXISTING_DATE = '2020-01-28';
|
||||||
const EXISTING_INTERVAL = 'PT7H20M';
|
public const EXISTING_INTERVAL = 'PT7H20M';
|
||||||
const NEW_DATE = '2020-04-01';
|
public const NEW_DATE = '2020-04-01';
|
||||||
const NEW_INTERVAL = 'PT7H59M';
|
public const NEW_INTERVAL = 'PT7H59M';
|
||||||
const RECORDS_COUNT = 61;
|
public const RECORDS_COUNT = 61;
|
||||||
|
|
||||||
protected PDO $pdoObject;
|
protected PDO $pdoObject;
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +42,8 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
{
|
{
|
||||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
$models = $repository->findAll();
|
$models = $repository->findAll();
|
||||||
$this->assertIsArray($models);
|
|
||||||
$this->assertContainsOnly(WorkingHours::class, $models);
|
$this->assertContainsOnlyInstancesOf(WorkingHours::class, $models);
|
||||||
$this->assertCount(self::RECORDS_COUNT, $models);
|
$this->assertCount(self::RECORDS_COUNT, $models);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,13 +53,13 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
public function valideFilterParameter(): array
|
public function valideFilterParameter(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[null, null, 61,],
|
[null, null, 61,],
|
||||||
['2020-04-01', null, 0,],
|
['2020-04-01', null, 0,],
|
||||||
['2020-04-01', '2020-04-30', 0,],
|
['2020-04-01', '2020-04-30', 0,],
|
||||||
[null, '2020-04-30', 61,],
|
[null, '2020-04-30', 61,],
|
||||||
['2020-03-01', null, 22,],
|
['2020-03-01', null, 22,],
|
||||||
['2020-03-01', '2020-03-31', 22,],
|
['2020-03-01', '2020-03-31', 22,],
|
||||||
['2020-03-01', '2020-03-07', 5,],
|
['2020-03-01', '2020-03-07', 5,],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,16 +68,15 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
* @param string|null $ende
|
* @param string|null $ende
|
||||||
* @param int $count
|
* @param int $count
|
||||||
*
|
*
|
||||||
* @dataProvider valideFilterParameter
|
|
||||||
*
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('valideFilterParameter')]
|
||||||
public function testFindAllWithValideParameter(?string $start, ?string $ende, int $count): void
|
public function testFindAllWithValideParameter(?string $start, ?string $ende, int $count): void
|
||||||
{
|
{
|
||||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
$models = $repository->findFiltered($start, $ende);
|
$models = $repository->findFiltered($start, $ende);
|
||||||
$this->assertIsArray($models);
|
|
||||||
$this->assertContainsOnly(WorkingHours::class, $models);
|
$this->assertContainsOnlyInstancesOf(WorkingHours::class, $models);
|
||||||
$this->assertCount($count, $models);
|
$this->assertCount($count, $models);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,23 +86,23 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
public function invalideFilterParameter(): array
|
public function invalideFilterParameter(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['2020-04-31',null],
|
['2020-04-31', null],
|
||||||
[null, '2020-04-31'],
|
[null, '2020-04-31'],
|
||||||
['2020-04-00','2020-04-31'],
|
['2020-04-00', '2020-04-31'],
|
||||||
['2020-04-01','2020-04-31'],
|
['2020-04-01', '2020-04-31'],
|
||||||
['2020-04-00','2020-04-30'],
|
['2020-04-00', '2020-04-30'],
|
||||||
//
|
//
|
||||||
['2020-04', null],
|
['2020-04', null],
|
||||||
[null, '2020-04'],
|
[null, '2020-04'],
|
||||||
['2020-04', '2020-04'],
|
['2020-04', '2020-04'],
|
||||||
['2020-04-01','2020-04'],
|
['2020-04-01', '2020-04'],
|
||||||
['2020-04', '2020-04-30'],
|
['2020-04', '2020-04-30'],
|
||||||
//
|
//
|
||||||
['2020', null],
|
['2020', null],
|
||||||
[null, '2020'],
|
[null, '2020'],
|
||||||
['2020', '2020'],
|
['2020', '2020'],
|
||||||
['2020-04-01','2020'],
|
['2020-04-01', '2020'],
|
||||||
['2020', '2020-04-30'],
|
['2020', '2020-04-30'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +110,9 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
* @param string|null $start
|
* @param string|null $start
|
||||||
* @param string|null $ende
|
* @param string|null $ende
|
||||||
*
|
*
|
||||||
* @dataProvider invalideFilterParameter
|
|
||||||
*
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
#[DataProvider('invalideFilterParameter')]
|
||||||
public function testFindAllWithInvalideParameter(?string $start, ?string $ende): void
|
public function testFindAllWithInvalideParameter(?string $start, ?string $ende): void
|
||||||
{
|
{
|
||||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
@@ -127,7 +127,6 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
{
|
{
|
||||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
$model = $repository->findByKey(self::EXISTING_DATE);
|
$model = $repository->findByKey(self::EXISTING_DATE);
|
||||||
$this->assertInstanceOf(WorkingHours::class, $model);
|
|
||||||
$this->assertEquals(new DateTime(self::EXISTING_DATE), $model->getWorkingDay());
|
$this->assertEquals(new DateTime(self::EXISTING_DATE), $model->getWorkingDay());
|
||||||
$this->assertEquals(new DateInterval(self::EXISTING_INTERVAL), $model->getWorkingTime());
|
$this->assertEquals(new DateInterval(self::EXISTING_INTERVAL), $model->getWorkingTime());
|
||||||
}
|
}
|
||||||
@@ -163,7 +162,6 @@ class WorkingHoursRepositoryTest extends Unit
|
|||||||
]);
|
]);
|
||||||
$repository->insert($model);
|
$repository->insert($model);
|
||||||
$model = $repository->findByKey(self::NEW_DATE);
|
$model = $repository->findByKey(self::NEW_DATE);
|
||||||
$this->assertInstanceOf(WorkingHours::class, $model);
|
|
||||||
$this->assertEquals(new DateTime(self::NEW_DATE), $model->getWorkingDay());
|
$this->assertEquals(new DateTime(self::NEW_DATE), $model->getWorkingDay());
|
||||||
$this->assertEquals(new DateInterval(self::NEW_INTERVAL), $model->getWorkingTime());
|
$this->assertEquals(new DateInterval(self::NEW_INTERVAL), $model->getWorkingTime());
|
||||||
$this->assertCount(self::RECORDS_COUNT + 1, $repository->findAll());
|
$this->assertCount(self::RECORDS_COUNT + 1, $repository->findAll());
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||||
|
|
||||||
|
use Codeception\Attribute\DataProvider;
|
||||||
use Codeception\Test\Unit;
|
use Codeception\Test\Unit;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PDO;
|
use PDO;use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||||
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;
|
||||||
@@ -25,7 +25,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array<array{string, int}>
|
||||||
*/
|
*/
|
||||||
public function listObjectProvider(): array
|
public function listObjectProvider(): array
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array<array{string, string, int, DateTime}>
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function existingObjectProvider(): array
|
public function existingObjectProvider(): array
|
||||||
@@ -50,7 +50,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array<array{string, string}>
|
||||||
*/
|
*/
|
||||||
public function notExistingObjectProvider(): array
|
public function notExistingObjectProvider(): array
|
||||||
{
|
{
|
||||||
@@ -61,49 +61,30 @@ class WorkingHoursViewRepositoryTest extends Unit
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#[DataProvider(('listObjectProvider'))]
|
||||||
* @param string $period_class
|
public function testFindAll(string $periodClass, int $countRecords): void
|
||||||
* @param int $count_records
|
|
||||||
*
|
|
||||||
* @dataProvider listObjectProvider
|
|
||||||
*/
|
|
||||||
public function testFindAll(string $period_class, int $count_records): void
|
|
||||||
{
|
{
|
||||||
$repository = new $period_class($this->pdoObject);
|
$repository = new $periodClass($this->pdoObject);
|
||||||
$models = $repository->findAll();
|
$models = $repository->findAll();
|
||||||
$this->assertIsArray($models);
|
$this->assertIsArray($models);
|
||||||
$this->assertContainsOnly(WorkingHoursView::class, $models);
|
$this->assertContainsOnlyInstancesOf(WorkingHoursView::class, $models);
|
||||||
$this->assertCount($count_records, $models);
|
$this->assertCount($countRecords, $models);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#[DataProvider(('existingObjectProvider'))]
|
||||||
*
|
public function testExistingFindByKey(string $periodClass, string $search, int $workingDays, DateTime $period): void
|
||||||
* @dataProvider existingObjectProvider
|
|
||||||
*
|
|
||||||
* @param string $period_class
|
|
||||||
* @param string $search
|
|
||||||
* @param int $workingDays
|
|
||||||
* @param DateTime $period
|
|
||||||
*/
|
|
||||||
public function testExistingFindByKey(string $period_class, string $search, int $workingDays, DateTime $period): void
|
|
||||||
{
|
{
|
||||||
$repository = new $period_class($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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#[DataProvider(('notExistingObjectProvider'))]
|
||||||
* @param string $period_class
|
public function testNotExistingFindByKey(string $periodClass, string $search): void
|
||||||
* @param string $search
|
|
||||||
*
|
|
||||||
* @dataProvider notExistingObjectProvider
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function testNotExistingFindByKey(string $period_class, string $search): void
|
|
||||||
{
|
{
|
||||||
$repository = new $period_class($this->pdoObject);
|
$repository = new $periodClass($this->pdoObject);
|
||||||
$this->expectException(RepositoryRecordNotFoundException::class);
|
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||||
$repository->findByKey($search);
|
$repository->findByKey($search);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user