From 3edfb97b969507071c0fd6eeab21866bee9cbdff Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Mon, 7 Nov 2022 15:52:09 +0100 Subject: [PATCH 1/2] Update --- config/packages/Centreon.yaml | 6 +- .../Common/UseCase/AbstractPresenter.php | 14 +- .../Common/UseCase/PresenterInterface.php | 1 - .../FindServicePresenterInterface.php | 4 +- .../Common/Presenter/AbstractFormatter.php | 48 +++++++ .../Common/Presenter/AbstractPresenter.php | 102 -------------- .../{CsvPresenter.php => CsvFormatter.php} | 22 +-- ...oadPresenter.php => DownloadFormatter.php} | 21 +-- .../Common/Presenter/JsonFormatter.php | 125 ++++++++++++++++++ .../Common/Presenter/JsonPresenter.php | 80 ----------- .../Presenter/PresenterFormatterInterface.php | 10 +- .../Api/FindNotificationPolicyPresenter.php | 3 +- .../User/Api/FindUsers/FindUsersPresenter.php | 10 +- .../Api/FindHost/FindHostPresenter.php | 35 +---- .../FindMetaServicePresenter.php | 113 ++++++---------- .../Api/FindService/FindServicePresenter.php | 121 +++++++---------- .../FindProviderConfigurationsPresenter.php | 5 +- .../FindConfigurationPresenter.php | 28 ++-- .../FindOpenIdConfigurationPresenter.php | 50 +++---- .../FindWebSSOConfigurationPresenter.php | 20 +-- .../User/UseCase/PatchUser/PatchUserTest.php | 4 +- .../Api/FindUsers/FindUsersPresenterTest.php | 3 +- .../LoginOpenIdSessionTest.php | 4 +- .../LogoutSessionControllerTest.php | 4 +- 24 files changed, 354 insertions(+), 479 deletions(-) create mode 100644 src/Core/Infrastructure/Common/Presenter/AbstractFormatter.php delete mode 100644 src/Core/Infrastructure/Common/Presenter/AbstractPresenter.php rename src/Core/Infrastructure/Common/Presenter/{CsvPresenter.php => CsvFormatter.php} (77%) rename src/Core/Infrastructure/Common/Presenter/{DownloadPresenter.php => DownloadFormatter.php} (84%) create mode 100644 src/Core/Infrastructure/Common/Presenter/JsonFormatter.php delete mode 100644 src/Core/Infrastructure/Common/Presenter/JsonPresenter.php diff --git a/config/packages/Centreon.yaml b/config/packages/Centreon.yaml index e92717bef82..b0671d34766 100644 --- a/config/packages/Centreon.yaml +++ b/config/packages/Centreon.yaml @@ -53,12 +53,12 @@ services: class: Centreon\Infrastructure\Serializer\ObjectConstructor public: false - json_presenter: - class: Core\Infrastructure\Common\Presenter\JsonPresenter + json_formatter: + class: Core\Infrastructure\Common\Presenter\JsonFormatter public: false Core\Infrastructure\Common\Presenter\PresenterFormatterInterface: - class: Core\Infrastructure\Common\Presenter\JsonPresenter + class: Core\Infrastructure\Common\Presenter\JsonFormatter public: false # Encryption diff --git a/src/Core/Application/Common/UseCase/AbstractPresenter.php b/src/Core/Application/Common/UseCase/AbstractPresenter.php index a0791af3433..03b951dfe2d 100644 --- a/src/Core/Application/Common/UseCase/AbstractPresenter.php +++ b/src/Core/Application/Common/UseCase/AbstractPresenter.php @@ -23,8 +23,6 @@ namespace Core\Application\Common\UseCase; use Symfony\Component\HttpFoundation\Response; -use Core\Application\Common\UseCase\PresenterInterface; -use Core\Application\Common\UseCase\ResponseStatusInterface; use Core\Infrastructure\Common\Presenter\PresenterFormatterInterface; abstract class AbstractPresenter implements PresenterInterface @@ -32,7 +30,7 @@ abstract class AbstractPresenter implements PresenterInterface /** * @var ResponseStatusInterface|null */ - protected $responseStatus; + protected ?ResponseStatusInterface $responseStatus = null; /** * @var mixed @@ -49,10 +47,9 @@ public function __construct(protected PresenterFormatterInterface $presenterForm /** * @inheritDoc */ - public function present(mixed $presentedData): void + public function present(mixed $data): void { - $this->presentedData = $presentedData; - $this->presenterFormatter->present($presentedData); + $this->presentedData = $data; } /** @@ -68,7 +65,9 @@ public function getPresentedData(): mixed */ public function show(): Response { - return $this->presenterFormatter->show(); + return ($this->responseStatus !== null) + ? $this->presenterFormatter->format($this->responseStatus) + : $this->presenterFormatter->format($this->presentedData); } /** @@ -77,7 +76,6 @@ public function show(): Response public function setResponseStatus(?ResponseStatusInterface $responseStatus): void { $this->responseStatus = $responseStatus; - $this->presenterFormatter->present($responseStatus); } /** diff --git a/src/Core/Application/Common/UseCase/PresenterInterface.php b/src/Core/Application/Common/UseCase/PresenterInterface.php index f0c6572e106..0f18194fc6a 100644 --- a/src/Core/Application/Common/UseCase/PresenterInterface.php +++ b/src/Core/Application/Common/UseCase/PresenterInterface.php @@ -23,7 +23,6 @@ namespace Core\Application\Common\UseCase; -use Core\Application\Common\UseCase\ResponseStatusInterface; use Symfony\Component\HttpFoundation\Response; interface PresenterInterface diff --git a/src/Core/Application/RealTime/UseCase/FindService/FindServicePresenterInterface.php b/src/Core/Application/RealTime/UseCase/FindService/FindServicePresenterInterface.php index f1f6ef9f1f6..b33260d6039 100644 --- a/src/Core/Application/RealTime/UseCase/FindService/FindServicePresenterInterface.php +++ b/src/Core/Application/RealTime/UseCase/FindService/FindServicePresenterInterface.php @@ -28,7 +28,7 @@ interface FindServicePresenterInterface extends PresenterInterface { /** * {@inheritDoc} - * @param FindServiceResponse $response + * @param FindServiceResponse $data */ - public function present(mixed $response): void; + public function present(mixed $data): void; } diff --git a/src/Core/Infrastructure/Common/Presenter/AbstractFormatter.php b/src/Core/Infrastructure/Common/Presenter/AbstractFormatter.php new file mode 100644 index 00000000000..0fc42340829 --- /dev/null +++ b/src/Core/Infrastructure/Common/Presenter/AbstractFormatter.php @@ -0,0 +1,48 @@ + + */ + protected array $responseHeaders = []; + + /** + * @param array $responseHeaders + */ + public function setResponseHeaders(array $responseHeaders): void + { + $this->responseHeaders = $responseHeaders; + } + + /** + * @return array + */ + public function getResponseHeaders(): array + { + return $this->responseHeaders; + } +} diff --git a/src/Core/Infrastructure/Common/Presenter/AbstractPresenter.php b/src/Core/Infrastructure/Common/Presenter/AbstractPresenter.php deleted file mode 100644 index 59a82cd9bed..00000000000 --- a/src/Core/Infrastructure/Common/Presenter/AbstractPresenter.php +++ /dev/null @@ -1,102 +0,0 @@ - - */ - protected array $responseHeaders = []; - - /** - * @param array $responseHeaders - */ - public function setResponseHeaders(array $responseHeaders): void - { - $this->responseHeaders = $responseHeaders; - } - - /** - * @return array - */ - public function getResponseHeaders(): array - { - return $this->responseHeaders; - } - - /** - * Format content on error - * - * @param mixed $data - * @param integer $code - * @return mixed[]|null - */ - protected function formatErrorContent(mixed $data, int $code): ?array - { - $content = null; - - if (is_a($data, ResponseStatusInterface::class)) { - $content = [ - 'code' => $code, - 'message' => $data->getMessage(), - ]; - if (is_a($data, BodyResponseInterface::class)) { - $content = array_merge($content, $data->getBody()); - } - } - - return $content; - } - - /** - * Generates json response with error message and http code - * @param mixed $data - * @param int $code - * @return JsonResponse - */ - protected function generateJsonErrorResponse(mixed $data, int $code): JsonResponse - { - $errorData = $this->formatErrorContent($data, $code); - - return $this->generateJsonResponse($errorData, $code); - } - - /** - * @param mixed $data - * @param int $code - * @return JsonResponse - */ - protected function generateJsonResponse(mixed $data, int $code): JsonResponse - { - if (is_a($data, \Generator::class)) { - $data = iterator_to_array($data); - } - return new JsonResponse($data, $code, $this->responseHeaders); - } -} diff --git a/src/Core/Infrastructure/Common/Presenter/CsvPresenter.php b/src/Core/Infrastructure/Common/Presenter/CsvFormatter.php similarity index 77% rename from src/Core/Infrastructure/Common/Presenter/CsvPresenter.php rename to src/Core/Infrastructure/Common/Presenter/CsvFormatter.php index 3040aebc139..a1fd356dc41 100644 --- a/src/Core/Infrastructure/Common/Presenter/CsvPresenter.php +++ b/src/Core/Infrastructure/Common/Presenter/CsvFormatter.php @@ -26,37 +26,27 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; -class CsvPresenter extends AbstractPresenter implements PresenterFormatterInterface +class CsvFormatter extends AbstractFormatter implements PresenterFormatterInterface { - private mixed $data = null; - - /** - * @inheritDoc - */ - public function present(mixed $data): void - { - $this->data = $data; - } - /** * @inheritDoc */ - public function show(): Response + public function format(mixed $data): Response { $response = new StreamedResponse(null, Response::HTTP_OK, $this->responseHeaders); - $response->setCallback(function () { + $response->setCallback(function () use ($data) { $handle = fopen('php://output', 'r+'); if ($handle === false) { throw new \RuntimeException('Unable to open the output buffer'); } $lineHeadersCreated = false; - foreach ($this->data as $data) { + foreach ($data as $oneData) { if (! $lineHeadersCreated) { - $columnNames = array_keys($data); + $columnNames = array_keys($oneData); fputcsv($handle, $columnNames, ';'); $lineHeadersCreated = true; } - $columnValues = array_values($data); + $columnValues = array_values($oneData); fputcsv($handle, $columnValues, ';'); } diff --git a/src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php b/src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php similarity index 84% rename from src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php rename to src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php index 6cdf98c3c5b..66bd6110396 100644 --- a/src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php +++ b/src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php @@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\Response; -class DownloadPresenter extends AbstractPresenter implements PresenterFormatterInterface, DownloadInterface +class DownloadFormatter extends AbstractFormatter implements PresenterFormatterInterface, DownloadInterface { private const CSV_FILE_EXTENSION = 'csv'; private const JSON_FILE_EXTENSION = 'json'; @@ -39,25 +39,18 @@ public function __construct(private PresenterFormatterInterface $presenter) /** * @inheritDoc */ - public function present(mixed $data): void + public function format(mixed $data): Response { - $this->presenter->present($data); $originalHeaders = $this->presenter->getResponseHeaders(); $originalHeaders['Content-Type'] = 'application/force-download'; $originalHeaders['Content-Disposition'] = 'attachment; filename="' . $this->generateDownloadFileName() . '"'; $this->presenter->setResponseHeaders($originalHeaders); + return $this->presenter->format($data); } /** - * @inheritDoc - */ - public function show(): Response - { - return $this->presenter->show(); - } - - /** - * @inheritDoc + * @param string $fileName + * @return void */ public function setDownloadFileName(string $fileName): void { @@ -72,8 +65,8 @@ public function setDownloadFileName(string $fileName): void private function generateDownloadFileExtension(): string { return match (get_class($this->presenter)) { - CsvPresenter::class => self::CSV_FILE_EXTENSION, - JsonPresenter::class => self::JSON_FILE_EXTENSION, + CsvFormatter::class => self::CSV_FILE_EXTENSION, + JsonFormatter::class => self::JSON_FILE_EXTENSION, default => '', }; } diff --git a/src/Core/Infrastructure/Common/Presenter/JsonFormatter.php b/src/Core/Infrastructure/Common/Presenter/JsonFormatter.php new file mode 100644 index 00000000000..9ab0a9cc144 --- /dev/null +++ b/src/Core/Infrastructure/Common/Presenter/JsonFormatter.php @@ -0,0 +1,125 @@ +debug('Data not found. Generating a not found response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_NOT_FOUND); + case is_a($data, ErrorResponse::class, false): + $this->debug('Data error. Generating an error response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_INTERNAL_SERVER_ERROR); + case is_a($data, InvalidArgumentResponse::class, false): + $this->debug('Invalid argument. Generating an error response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_BAD_REQUEST); + case is_a($data, UnauthorizedResponse::class, false): + $this->debug('Unauthorized. Generating an error response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_UNAUTHORIZED); + case is_a($data, PaymentRequiredResponse::class, false): + $this->debug('Payment required. Generating an error response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_PAYMENT_REQUIRED); + case is_a($data, ForbiddenResponse::class, false): + $this->debug('Forbidden. Generating an error response'); + return $this->generateJsonErrorResponse($data, JsonResponse::HTTP_FORBIDDEN); + case is_a($data, CreatedResponse::class, false): + return $this->generateJsonResponse(null, JsonResponse::HTTP_CREATED); + case is_a($data, NoContentResponse::class, false): + return $this->generateJsonResponse(null, JsonResponse::HTTP_NO_CONTENT); + default: + return $this->generateJsonResponse($data, JsonResponse::HTTP_OK); + } + } + + /** + * Generates json response with error message and http code + * @param mixed $data + * @param int $code + * @return JsonResponse + */ + private function generateJsonErrorResponse(mixed $data, int $code): JsonResponse + { + $errorData = $this->formatErrorContent($data, $code); + + return $this->generateJsonResponse($errorData, $code); + } + + /** + * @param mixed $data + * @param int $code + * @return JsonResponse + */ + private function generateJsonResponse(mixed $data, int $code): JsonResponse + { + if (is_a($data, \Generator::class)) { + $data = iterator_to_array($data); + } + return new JsonResponse($data, $code, $this->responseHeaders); + } + + /** + * Format content on error + * + * @param mixed $data + * @param integer $code + * @return mixed[]|null + */ + protected function formatErrorContent(mixed $data, int $code): ?array + { + $content = null; + + if (is_a($data, ResponseStatusInterface::class)) { + $content = [ + 'code' => $code, + 'message' => $data->getMessage(), + ]; + if (is_a($data, BodyResponseInterface::class)) { + $content = array_merge($content, $data->getBody()); + } + } + + return $content; + } +} diff --git a/src/Core/Infrastructure/Common/Presenter/JsonPresenter.php b/src/Core/Infrastructure/Common/Presenter/JsonPresenter.php deleted file mode 100644 index e798bc66731..00000000000 --- a/src/Core/Infrastructure/Common/Presenter/JsonPresenter.php +++ /dev/null @@ -1,80 +0,0 @@ -data = $data; - } - - /** - * @return JsonResponse - */ - public function show(): JsonResponse - { - switch (true) { - case is_a($this->data, NotFoundResponse::class, false): - $this->debug('Data not found. Generating a not found response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_NOT_FOUND); - case is_a($this->data, ErrorResponse::class, false): - $this->debug('Data error. Generating an error response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_INTERNAL_SERVER_ERROR); - case is_a($this->data, InvalidArgumentResponse::class, false): - $this->debug('Invalid argument. Generating an error response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_BAD_REQUEST); - case is_a($this->data, UnauthorizedResponse::class, false): - $this->debug('Unauthorized. Generating an error response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_UNAUTHORIZED); - case is_a($this->data, PaymentRequiredResponse::class, false): - $this->debug('Payment required. Generating an error response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_PAYMENT_REQUIRED); - case is_a($this->data, ForbiddenResponse::class, false): - $this->debug('Forbidden. Generating an error response'); - return $this->generateJsonErrorResponse($this->data, JsonResponse::HTTP_FORBIDDEN); - case is_a($this->data, CreatedResponse::class, false): - return $this->generateJsonResponse(null, JsonResponse::HTTP_CREATED); - case is_a($this->data, NoContentResponse::class, false): - return $this->generateJsonResponse(null, JsonResponse::HTTP_NO_CONTENT); - default: - return $this->generateJsonResponse($this->data, JsonResponse::HTTP_OK); - } - } -} diff --git a/src/Core/Infrastructure/Common/Presenter/PresenterFormatterInterface.php b/src/Core/Infrastructure/Common/Presenter/PresenterFormatterInterface.php index bbb671bdec0..bea7071cae0 100644 --- a/src/Core/Infrastructure/Common/Presenter/PresenterFormatterInterface.php +++ b/src/Core/Infrastructure/Common/Presenter/PresenterFormatterInterface.php @@ -27,22 +27,18 @@ interface PresenterFormatterInterface { /** - * @param mixed[] $responseHeaders + * @param array $responseHeaders */ public function setResponseHeaders(array $responseHeaders): void; /** - * @return mixed[] + * @return array */ public function getResponseHeaders(): array; /** * @param mixed $data - */ - public function present(mixed $data): void; - - /** * @return Response */ - public function show(): Response; + public function format(mixed $data): Response; } diff --git a/src/Core/Infrastructure/Configuration/NotificationPolicy/Api/FindNotificationPolicyPresenter.php b/src/Core/Infrastructure/Configuration/NotificationPolicy/Api/FindNotificationPolicyPresenter.php index 0765615edd1..22c9cdc1422 100644 --- a/src/Core/Infrastructure/Configuration/NotificationPolicy/Api/FindNotificationPolicyPresenter.php +++ b/src/Core/Infrastructure/Configuration/NotificationPolicy/Api/FindNotificationPolicyPresenter.php @@ -40,6 +40,7 @@ public function __construct( private ContactGroupHypermediaCreator $contactGroupHypermediaCreator, protected PresenterFormatterInterface $presenterFormatter ) { + parent::__construct($presenterFormatter); } /** @@ -75,6 +76,6 @@ public function present(mixed $response): void $presenterResponse['is_notification_enabled'] = $response->isNotificationEnabled; - $this->presenterFormatter->present($presenterResponse); + parent::present($presenterResponse); } } diff --git a/src/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenter.php b/src/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenter.php index 0c309a11d08..6c32747108e 100644 --- a/src/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenter.php +++ b/src/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenter.php @@ -23,7 +23,6 @@ namespace Core\Infrastructure\Configuration\User\Api\FindUsers; use Core\Application\Common\UseCase\AbstractPresenter; -use Core\Application\Configuration\User\UseCase\FindUsers\FindUsersResponse; use Core\Application\Configuration\User\UseCase\FindUsers\FindUsersPresenterInterface; use Centreon\Domain\RequestParameters\Interfaces\RequestParametersInterface; use Core\Infrastructure\Common\Presenter\PresenterFormatterInterface; @@ -38,17 +37,16 @@ public function __construct( private RequestParametersInterface $requestParameters, protected PresenterFormatterInterface $presenterFormatter, ) { + parent::__construct($presenterFormatter); } /** * @inheritDoc */ - public function present(mixed $response): void + public function present(mixed $data): void { - $presenterResponse = $response->users; - - $this->presenterFormatter->present([ - 'result' => $presenterResponse, + parent::present([ + 'result' => $data->users, 'meta' => $this->requestParameters->toArray(), ]); } diff --git a/src/Core/Infrastructure/RealTime/Api/FindHost/FindHostPresenter.php b/src/Core/Infrastructure/RealTime/Api/FindHost/FindHostPresenter.php index a1285805944..a8edf2b4314 100644 --- a/src/Core/Infrastructure/RealTime/Api/FindHost/FindHostPresenter.php +++ b/src/Core/Infrastructure/RealTime/Api/FindHost/FindHostPresenter.php @@ -38,11 +38,6 @@ class FindHostPresenter extends AbstractPresenter implements FindHostPresenterIn use PresenterTrait; use HttpUrlTrait; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * @param HypermediaCreator $hypermediaCreator * @param PresenterFormatterInterface $presenterFormatter @@ -51,6 +46,7 @@ public function __construct( private HypermediaCreator $hypermediaCreator, protected PresenterFormatterInterface $presenterFormatter ) { + parent::__construct($presenterFormatter); } /** @@ -172,33 +168,6 @@ public function present(mixed $response): void $presenterResponse['links']['uris'] = $this->hypermediaCreator->createInternalUris($parameters); - $this->presenterFormatter->present($presenterResponse); - } - - /** - * @inheritDoc - */ - public function show(): Response - { - if ($this->getResponseStatus() !== null) { - $this->presenterFormatter->present($this->getResponseStatus()); - } - return $this->presenterFormatter->show(); - } - - /** - * @inheritDoc - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @inheritDoc - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; + parent::present($presenterResponse); } } diff --git a/src/Core/Infrastructure/RealTime/Api/FindMetaService/FindMetaServicePresenter.php b/src/Core/Infrastructure/RealTime/Api/FindMetaService/FindMetaServicePresenter.php index e133b67f59c..89134e53213 100644 --- a/src/Core/Infrastructure/RealTime/Api/FindMetaService/FindMetaServicePresenter.php +++ b/src/Core/Infrastructure/RealTime/Api/FindMetaService/FindMetaServicePresenter.php @@ -35,11 +35,6 @@ class FindMetaServicePresenter extends AbstractPresenter implements FindMetaServ { use PresenterTrait; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * @param HypermediaCreator $hypermediaCreator * @param PresenterFormatterInterface $presenterFormatter @@ -48,48 +43,49 @@ public function __construct( private HypermediaCreator $hypermediaCreator, protected PresenterFormatterInterface $presenterFormatter ) { + parent::__construct($presenterFormatter); } /** * {@inheritDoc} - * @param FindMetaServiceResponse $response + * @param FindMetaServiceResponse $data */ - public function present(mixed $response): void + public function present(mixed $data): void { $presenterResponse = [ - 'uuid' => 'm' . $response->metaId, - 'id' => $response->metaId, - 'name' => $response->name, + 'uuid' => 'm' . $data->metaId, + 'id' => $data->metaId, + 'name' => $data->name, 'type' => 'metaservice', 'short_type' => 'm', - 'status' => $response->status, - 'in_downtime' => $response->isInDowntime, - 'acknowledged' => $response->isAcknowledged, - 'flapping' => $response->isFlapping, - 'performance_data' => $response->performanceData, - 'information' => $response->output, - 'command_line' => $response->commandLine, - 'notification_number' => $response->notificationNumber, - 'latency' => $response->latency, - 'percent_state_change' => $response->statusChangePercentage, - 'passive_checks' => $response->hasPassiveChecks, - 'execution_time' => $response->executionTime, - 'active_checks' => $response->hasActiveChecks, + 'status' => $data->status, + 'in_downtime' => $data->isInDowntime, + 'acknowledged' => $data->isAcknowledged, + 'flapping' => $data->isFlapping, + 'performance_data' => $data->performanceData, + 'information' => $data->output, + 'command_line' => $data->commandLine, + 'notification_number' => $data->notificationNumber, + 'latency' => $data->latency, + 'percent_state_change' => $data->statusChangePercentage, + 'passive_checks' => $data->hasPassiveChecks, + 'execution_time' => $data->executionTime, + 'active_checks' => $data->hasActiveChecks, 'groups' => [], 'parent' => null, - 'monitoring_server_name' => $response->monitoringServerName, - 'calculation_type' => $response->calculationType, + 'monitoring_server_name' => $data->monitoringServerName, + 'calculation_type' => $data->calculationType, ]; $acknowledgement = null; - if (!empty($response->acknowledgement)) { + if (!empty($data->acknowledgement)) { /** * Convert Acknowledgement dates into ISO 8601 format */ - $acknowledgement = $response->acknowledgement; - $acknowledgement['entry_time'] = $this->formatDateToIso8601($response->acknowledgement['entry_time']); - $acknowledgement['deletion_time'] = $this->formatDateToIso8601($response->acknowledgement['deletion_time']); + $acknowledgement = $data->acknowledgement; + $acknowledgement['entry_time'] = $this->formatDateToIso8601($data->acknowledgement['entry_time']); + $acknowledgement['deletion_time'] = $this->formatDateToIso8601($data->acknowledgement['deletion_time']); } $presenterResponse['acknowledgement'] = $acknowledgement; @@ -99,7 +95,7 @@ public function present(mixed $response): void */ $formattedDatesDowntimes = []; - foreach ($response->downtimes as $key => $downtime) { + foreach ($data->downtimes as $key => $downtime) { $formattedDatesDowntimes[$key] = $downtime; $formattedDatesDowntimes[$key]['start_time'] = $this->formatDateToIso8601($downtime['start_time']); $formattedDatesDowntimes[$key]['end_time'] = $this->formatDateToIso8601($downtime['end_time']); @@ -116,35 +112,35 @@ public function present(mixed $response): void /** * Calculate the duration */ - $presenterResponse['duration'] = $response->lastStatusChange !== null - ? \CentreonDuration::toString(time() - $response->lastStatusChange->getTimestamp()) + $presenterResponse['duration'] = $data->lastStatusChange !== null + ? \CentreonDuration::toString(time() - $data->lastStatusChange->getTimestamp()) : null; /** * Convert dates to ISO 8601 format */ - $presenterResponse['next_check'] = $this->formatDateToIso8601($response->nextCheck); - $presenterResponse['last_check'] = $this->formatDateToIso8601($response->lastCheck); - $presenterResponse['last_time_with_no_issue'] = $this->formatDateToIso8601($response->lastTimeOk); - $presenterResponse['last_status_change'] = $this->formatDateToIso8601($response->lastStatusChange); - $presenterResponse['last_notification'] = $this->formatDateToIso8601($response->lastNotification); + $presenterResponse['next_check'] = $this->formatDateToIso8601($data->nextCheck); + $presenterResponse['last_check'] = $this->formatDateToIso8601($data->lastCheck); + $presenterResponse['last_time_with_no_issue'] = $this->formatDateToIso8601($data->lastTimeOk); + $presenterResponse['last_status_change'] = $this->formatDateToIso8601($data->lastStatusChange); + $presenterResponse['last_notification'] = $this->formatDateToIso8601($data->lastNotification); /** * Creating the 'tries' entry */ - $tries = $response->checkAttempts . '/' . $response->maxCheckAttempts; - $statusType = $response->status['type'] === 0 ? 'S' : 'H'; + $tries = $data->checkAttempts . '/' . $data->maxCheckAttempts; + $statusType = $data->status['type'] === 0 ? 'S' : 'H'; $presenterResponse['tries'] = $tries . '(' . $statusType . ')'; /** * Creating Hypermedias */ $parameters = [ - 'type' => $response->type, - 'hostId' => $response->hostId, - 'serviceId' => $response->serviceId, - 'internalId' => $response->metaId, - 'hasGraphData' => $response->hasGraphData + 'type' => $data->type, + 'hostId' => $data->hostId, + 'serviceId' => $data->serviceId, + 'internalId' => $data->metaId, + 'hasGraphData' => $data->hasGraphData ]; $endpoints = $this->hypermediaCreator->createEndpoints($parameters); @@ -161,33 +157,6 @@ public function present(mixed $response): void $presenterResponse['links']['uris'] = $this->hypermediaCreator->createInternalUris($parameters); - $this->presenterFormatter->present($presenterResponse); - } - - /** - * @inheritDoc - */ - public function show(): Response - { - if ($this->getResponseStatus() !== null) { - $this->presenterFormatter->present($this->getResponseStatus()); - } - return $this->presenterFormatter->show(); - } - - /** - * @inheritDoc - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @inheritDoc - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; + parent::present($presenterResponse); } } diff --git a/src/Core/Infrastructure/RealTime/Api/FindService/FindServicePresenter.php b/src/Core/Infrastructure/RealTime/Api/FindService/FindServicePresenter.php index 21fbf100629..84a4047a957 100644 --- a/src/Core/Infrastructure/RealTime/Api/FindService/FindServicePresenter.php +++ b/src/Core/Infrastructure/RealTime/Api/FindService/FindServicePresenter.php @@ -37,11 +37,6 @@ class FindServicePresenter extends AbstractPresenter implements FindServicePrese use PresenterTrait; use HttpUrlTrait; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * @param HypermediaCreator $hypermediaCreator * @param PresenterFormatterInterface $presenterFormatter @@ -50,39 +45,40 @@ public function __construct( private HypermediaCreator $hypermediaCreator, protected PresenterFormatterInterface $presenterFormatter ) { + parent::__construct($presenterFormatter); } /** * {@inheritDoc} - * @param FindServiceResponse $response + * @param FindServiceResponse $data */ - public function present(mixed $response): void + public function present(mixed $data): void { $presenterResponse = [ - 'uuid' => 'h' . $response->hostId . '-s' . $response->serviceId, - 'id' => $response->serviceId, - 'name' => $response->name, + 'uuid' => 'h' . $data->hostId . '-s' . $data->serviceId, + 'id' => $data->serviceId, + 'name' => $data->name, 'type' => 'service', 'short_type' => 's', - 'status' => $response->status, - 'in_downtime' => $response->isInDowntime, - 'acknowledged' => $response->isAcknowledged, - 'flapping' => $response->isFlapping, - 'performance_data' => $response->performanceData, - 'information' => $response->output, - 'command_line' => $response->commandLine, - 'notification_number' => $response->notificationNumber, - 'latency' => $response->latency, - 'percent_state_change' => $response->statusChangePercentage, - 'passive_checks' => $response->hasPassiveChecks, - 'execution_time' => $response->executionTime, - 'active_checks' => $response->hasActiveChecks, - 'icon' => $response->icon, - 'groups' => $this->hypermediaCreator->convertGroupsForPresenter($response), - 'parent' => $response->host, - 'monitoring_server_name' => $response->host['monitoring_server_name'], - 'categories' => $this->hypermediaCreator->convertCategoriesForPresenter($response), - 'severity' => $response->severity, + 'status' => $data->status, + 'in_downtime' => $data->isInDowntime, + 'acknowledged' => $data->isAcknowledged, + 'flapping' => $data->isFlapping, + 'performance_data' => $data->performanceData, + 'information' => $data->output, + 'command_line' => $data->commandLine, + 'notification_number' => $data->notificationNumber, + 'latency' => $data->latency, + 'percent_state_change' => $data->statusChangePercentage, + 'passive_checks' => $data->hasPassiveChecks, + 'execution_time' => $data->executionTime, + 'active_checks' => $data->hasActiveChecks, + 'icon' => $data->icon, + 'groups' => $this->hypermediaCreator->convertGroupsForPresenter($data), + 'parent' => $data->host, + 'monitoring_server_name' => $data->host['monitoring_server_name'], + 'categories' => $this->hypermediaCreator->convertCategoriesForPresenter($data), + 'severity' => $data->severity, ]; if ($presenterResponse['severity'] !== null) { @@ -90,18 +86,18 @@ public function present(mixed $response): void * normalize the URL to the severity icon */ $presenterResponse['severity']['icon']['url'] = $this->getBaseUri() - . '/img/media/' . $response->severity['icon']['url']; + . '/img/media/' . $data->severity['icon']['url']; } $acknowledgement = null; - if (!empty($response->acknowledgement)) { + if (!empty($data->acknowledgement)) { /** * Convert Acknowledgement dates into ISO 8601 format */ - $acknowledgement = $response->acknowledgement; - $acknowledgement['entry_time'] = $this->formatDateToIso8601($response->acknowledgement['entry_time']); - $acknowledgement['deletion_time'] = $this->formatDateToIso8601($response->acknowledgement['deletion_time']); + $acknowledgement = $data->acknowledgement; + $acknowledgement['entry_time'] = $this->formatDateToIso8601($data->acknowledgement['entry_time']); + $acknowledgement['deletion_time'] = $this->formatDateToIso8601($data->acknowledgement['deletion_time']); } $presenterResponse['acknowledgement'] = $acknowledgement; @@ -111,7 +107,7 @@ public function present(mixed $response): void */ $formattedDatesDowntimes = []; - foreach ($response->downtimes as $key => $downtime) { + foreach ($data->downtimes as $key => $downtime) { $formattedDatesDowntimes[$key] = $downtime; $formattedDatesDowntimes[$key]['start_time'] = $this->formatDateToIso8601($downtime['start_time']); $formattedDatesDowntimes[$key]['end_time'] = $this->formatDateToIso8601($downtime['end_time']); @@ -128,34 +124,34 @@ public function present(mixed $response): void /** * Calculate the duration */ - $presenterResponse['duration'] = $response->lastStatusChange !== null - ? \CentreonDuration::toString(time() - $response->lastStatusChange->getTimestamp()) + $presenterResponse['duration'] = $data->lastStatusChange !== null + ? \CentreonDuration::toString(time() - $data->lastStatusChange->getTimestamp()) : null; /** * Convert dates to ISO 8601 format */ - $presenterResponse['next_check'] = $this->formatDateToIso8601($response->nextCheck); - $presenterResponse['last_check'] = $this->formatDateToIso8601($response->lastCheck); - $presenterResponse['last_time_with_no_issue'] = $this->formatDateToIso8601($response->lastTimeOk); - $presenterResponse['last_status_change'] = $this->formatDateToIso8601($response->lastStatusChange); - $presenterResponse['last_notification'] = $this->formatDateToIso8601($response->lastNotification); + $presenterResponse['next_check'] = $this->formatDateToIso8601($data->nextCheck); + $presenterResponse['last_check'] = $this->formatDateToIso8601($data->lastCheck); + $presenterResponse['last_time_with_no_issue'] = $this->formatDateToIso8601($data->lastTimeOk); + $presenterResponse['last_status_change'] = $this->formatDateToIso8601($data->lastStatusChange); + $presenterResponse['last_notification'] = $this->formatDateToIso8601($data->lastNotification); /** * Creating the 'tries' entry */ - $tries = $response->checkAttempts . '/' . $response->maxCheckAttempts; - $statusType = $response->status['type'] === 0 ? 'S' : 'H'; + $tries = $data->checkAttempts . '/' . $data->maxCheckAttempts; + $statusType = $data->status['type'] === 0 ? 'S' : 'H'; $presenterResponse['tries'] = $tries . '(' . $statusType . ')'; /** * Creating Hypermedias */ $parameters = [ - 'type' => $response->type, - 'hostId' => $response->hostId, - 'serviceId' => $response->serviceId, - 'hasGraphData' => $response->hasGraphData + 'type' => $data->type, + 'hostId' => $data->hostId, + 'serviceId' => $data->serviceId, + 'hasGraphData' => $data->hasGraphData ]; $endpoints = $this->hypermediaCreator->createEndpoints($parameters); @@ -171,33 +167,6 @@ public function present(mixed $response): void $presenterResponse['links']['uris'] = $this->hypermediaCreator->createInternalUris($parameters); - $this->presenterFormatter->present($presenterResponse); - } - - /** - * @inheritDoc - */ - public function show(): Response - { - if ($this->getResponseStatus() !== null) { - $this->presenterFormatter->present($this->getResponseStatus()); - } - return $this->presenterFormatter->show(); - } - - /** - * @inheritDoc - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @inheritDoc - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; + parent::present($presenterResponse); } } diff --git a/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php b/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php index 52077cf01e7..1db6841b959 100644 --- a/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php +++ b/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php @@ -41,7 +41,7 @@ class FindProviderConfigurationsPresenter extends AbstractPresenter implements /** * @var ProviderPresenterInterface[] */ - private $providerPresenters; + private array $providerPresenters; /** * @param \Traversable $presenters @@ -51,6 +51,7 @@ public function __construct( \Traversable $presenters, protected PresenterFormatterInterface $presenterFormatter ) { + parent::__construct($presenterFormatter); if (iterator_count($presenters) === 0) { throw new NotFoundException(_('No provider presenters could be found')); } @@ -72,6 +73,6 @@ public function present(mixed $data): void } } } - $this->presenterFormatter->present($formattedResponse); + parent::present($formattedResponse); } } diff --git a/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php b/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php index 79520ba10bc..ab7c06847e8 100644 --- a/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php +++ b/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php @@ -30,28 +30,28 @@ class FindConfigurationPresenter extends AbstractPresenter implements FindConfig { /** * {@inheritDoc} - * @param FindConfigurationResponse $response + * @param FindConfigurationResponse $data */ - public function present(mixed $response): void + public function present(mixed $data): void { $presenterResponse = [ 'password_security_policy' => [ - 'password_min_length' => $response->passwordMinimumLength, - 'has_uppercase' => $response->hasUppercase, - 'has_lowercase' => $response->hasLowercase, - 'has_number' => $response->hasNumber, - 'has_special_character' => $response->hasSpecialCharacter, - 'attempts' => $response->attempts, - 'blocking_duration' => $response->blockingDuration, + 'password_min_length' => $data->passwordMinimumLength, + 'has_uppercase' => $data->hasUppercase, + 'has_lowercase' => $data->hasLowercase, + 'has_number' => $data->hasNumber, + 'has_special_character' => $data->hasSpecialCharacter, + 'attempts' => $data->attempts, + 'blocking_duration' => $data->blockingDuration, 'password_expiration' => [ - 'expiration_delay' => $response->passwordExpirationDelay, - 'excluded_users' => $response->passwordExpirationExcludedUserAliases, + 'expiration_delay' => $data->passwordExpirationDelay, + 'excluded_users' => $data->passwordExpirationExcludedUserAliases, ], - 'can_reuse_passwords' => $response->canReusePasswords, - 'delay_before_new_password' => $response->delayBeforeNewPassword, + 'can_reuse_passwords' => $data->canReusePasswords, + 'delay_before_new_password' => $data->delayBeforeNewPassword, ] ]; - $this->presenterFormatter->present($presenterResponse); + parent::present($presenterResponse); } } diff --git a/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php b/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php index 83bbfd9c43f..80b29504eae 100644 --- a/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php +++ b/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php @@ -33,35 +33,35 @@ class FindOpenIdConfigurationPresenter extends AbstractPresenter implements Find { /** * {@inheritDoc} - * @param FindOpenIdConfigurationResponse $response + * @param FindOpenIdConfigurationResponse $data */ - public function present(mixed $response): void + public function present(mixed $data): void { $presenterResponse = [ - 'is_active' => $response->isActive, - 'is_forced' => $response->isForced, - 'base_url' => $response->baseUrl, - 'authorization_endpoint' => $response->authorizationEndpoint, - 'token_endpoint' => $response->tokenEndpoint, - 'introspection_token_endpoint' => $response->introspectionTokenEndpoint, - 'userinfo_endpoint' => $response->userInformationEndpoint, - 'endsession_endpoint' => $response->endSessionEndpoint, - 'connection_scopes' => $response->connectionScopes, - 'login_claim' => $response->loginClaim, - 'client_id' => $response->clientId, - 'client_secret' => $response->clientSecret, - 'authentication_type' => $response->authenticationType, - 'verify_peer' => $response->verifyPeer, - 'auto_import' => $response->isAutoImportEnabled, - 'contact_template' => $response->contactTemplate, - 'email_bind_attribute' => $response->emailBindAttribute, - 'fullname_bind_attribute' => $response->userNameBindAttribute, - 'contact_group' => $response->contactGroup, - 'roles_mapping' => $response->aclConditions, - 'authentication_conditions' => $response->authenticationConditions, - 'groups_mapping' => $response->groupsMapping + 'is_active' => $data->isActive, + 'is_forced' => $data->isForced, + 'base_url' => $data->baseUrl, + 'authorization_endpoint' => $data->authorizationEndpoint, + 'token_endpoint' => $data->tokenEndpoint, + 'introspection_token_endpoint' => $data->introspectionTokenEndpoint, + 'userinfo_endpoint' => $data->userInformationEndpoint, + 'endsession_endpoint' => $data->endSessionEndpoint, + 'connection_scopes' => $data->connectionScopes, + 'login_claim' => $data->loginClaim, + 'client_id' => $data->clientId, + 'client_secret' => $data->clientSecret, + 'authentication_type' => $data->authenticationType, + 'verify_peer' => $data->verifyPeer, + 'auto_import' => $data->isAutoImportEnabled, + 'contact_template' => $data->contactTemplate, + 'email_bind_attribute' => $data->emailBindAttribute, + 'fullname_bind_attribute' => $data->userNameBindAttribute, + 'contact_group' => $data->contactGroup, + 'roles_mapping' => $data->aclConditions, + 'authentication_conditions' => $data->authenticationConditions, + 'groups_mapping' => $data->groupsMapping ]; - $this->presenterFormatter->present($presenterResponse); + parent::present($presenterResponse); } } diff --git a/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php b/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php index 9bc9dd86036..97ebbbe7db8 100644 --- a/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php +++ b/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php @@ -33,20 +33,20 @@ class FindWebSSOConfigurationPresenter extends AbstractPresenter implements Find { /** * {@inheritDoc} - * @param FindWebSSOConfigurationResponse $response + * @param FindWebSSOConfigurationResponse $data */ - public function present(mixed $response): void + public function present(mixed $data): void { $presenterResponse = [ - 'is_active' => $response->isActive, - 'is_forced' => $response->isForced, - 'trusted_client_addresses' => $response->trustedClientAddresses, - 'blacklist_client_addresses' => $response->blacklistClientAddresses, - 'login_header_attribute' => $response->loginHeaderAttribute, - 'pattern_matching_login' => $response->patternMatchingLogin, - 'pattern_replace_login' => $response->patternReplaceLogin + 'is_active' => $data->isActive, + 'is_forced' => $data->isForced, + 'trusted_client_addresses' => $data->trustedClientAddresses, + 'blacklist_client_addresses' => $data->blacklistClientAddresses, + 'login_header_attribute' => $data->loginHeaderAttribute, + 'pattern_matching_login' => $data->patternMatchingLogin, + 'pattern_replace_login' => $data->patternReplaceLogin ]; - $this->presenterFormatter->present($presenterResponse); + parent::present($presenterResponse); } } diff --git a/tests/php/Core/Application/Configuration/User/UseCase/PatchUser/PatchUserTest.php b/tests/php/Core/Application/Configuration/User/UseCase/PatchUser/PatchUserTest.php index b2d62ce615e..44d448560cb 100644 --- a/tests/php/Core/Application/Configuration/User/UseCase/PatchUser/PatchUserTest.php +++ b/tests/php/Core/Application/Configuration/User/UseCase/PatchUser/PatchUserTest.php @@ -32,7 +32,7 @@ use Core\Application\Configuration\User\UseCase\PatchUser\PatchUser; use Core\Application\Configuration\User\UseCase\PatchUser\PatchUserRequest; use Core\Domain\Configuration\User\Model\User; -use Core\Infrastructure\Common\Presenter\JsonPresenter; +use Core\Infrastructure\Common\Presenter\JsonFormatter; use Core\Infrastructure\Configuration\User\Api\PatchUser\PatchUserPresenter; beforeEach(function () { @@ -43,7 +43,7 @@ $this->request = new PatchUserRequest(); $this->request->theme = 'light'; $this->request->userId = 1; - $this->presenter = new PatchUserPresenter(new JsonPresenter()); + $this->presenter = new PatchUserPresenter(new JsonFormatter()); }); it('tests the error message when user is not found', function () { diff --git a/tests/php/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenterTest.php b/tests/php/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenterTest.php index e86353b7607..e2821156d33 100644 --- a/tests/php/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenterTest.php +++ b/tests/php/Core/Infrastructure/Configuration/User/Api/FindUsers/FindUsersPresenterTest.php @@ -88,7 +88,7 @@ public function testFindControllerExecute(): void ->willReturn($requestParameterValues); $this->presenterFormatter->expects($this->once()) - ->method('present') + ->method('format') ->with( [ 'result' => [$user], @@ -98,5 +98,6 @@ public function testFindControllerExecute(): void $response = new FindUsersResponse([$userModel]); $presenter->present($response); + $presenter->show(); } } diff --git a/tests/php/Core/Security/Authentication/Application/UseCase/LoginOpenIdSession/LoginOpenIdSessionTest.php b/tests/php/Core/Security/Authentication/Application/UseCase/LoginOpenIdSession/LoginOpenIdSessionTest.php index edbb170563b..359bd5d0ac6 100644 --- a/tests/php/Core/Security/Authentication/Application/UseCase/LoginOpenIdSession/LoginOpenIdSessionTest.php +++ b/tests/php/Core/Security/Authentication/Application/UseCase/LoginOpenIdSession/LoginOpenIdSessionTest.php @@ -31,7 +31,7 @@ use Core\Contact\Domain\Model\ContactTemplate; use Core\Application\Common\UseCase\ErrorResponse; use Symfony\Component\HttpFoundation\RequestStack; -use Core\Infrastructure\Common\Presenter\JsonPresenter; +use Core\Infrastructure\Common\Presenter\JsonFormatter; use Core\Security\AccessGroup\Domain\Model\AccessGroup; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Menu\Interfaces\MenuServiceInterface; @@ -93,7 +93,7 @@ $this->authenticationRepository = $this->createMock(AuthenticationRepositoryInterface::class); $this->sessionRepository = $this->createMock(SessionRepositoryInterface::class); $this->dataStorageEngine = $this->createMock(DataStorageEngineInterface::class); - $this->formatter = $this->createMock(JsonPresenter::class); + $this->formatter = $this->createMock(JsonFormatter::class); $this->presenter = new LoginPresenter($this->formatter); $this->contact = $this->createMock(ContactInterface::class); $this->authenticationTokens = $this->createMock(AuthenticationTokens::class); diff --git a/tests/php/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionControllerTest.php b/tests/php/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionControllerTest.php index b1d8c1c74c9..e0d787a0f4c 100644 --- a/tests/php/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionControllerTest.php +++ b/tests/php/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionControllerTest.php @@ -30,7 +30,7 @@ use Core\Security\Authentication\Application\UseCase\LogoutSession\LogoutSession; use Core\Security\Authentication\Infrastructure\Api\LogoutSession\LogoutSessionController; use Core\Security\Authentication\Infrastructure\Api\LogoutSession\LogoutSessionPresenter; -use Core\Infrastructure\Common\Presenter\JsonPresenter; +use Core\Infrastructure\Common\Presenter\JsonFormatter; use Core\Application\Common\UseCase\NoContentResponse; use Core\Application\Common\UseCase\ErrorResponse; @@ -55,7 +55,7 @@ public function setUp(): void { $this->request = $this->createMock(Request::class); $this->useCase = $this->createMock(LogoutSession::class); - $this->logoutSessionPresenter = new LogoutSessionPresenter(new JsonPresenter()); + $this->logoutSessionPresenter = new LogoutSessionPresenter(new JsonFormatter()); } /** From b3f7ff9ce090339e7cc9cab24fb422bce7fd940b Mon Sep 17 00:00:00 2001 From: Laurent Calvet Date: Tue, 8 Nov 2022 15:35:04 +0100 Subject: [PATCH 2/2] Fix tests in error --- config/packages/Centreon.yaml | 2 +- ...oadFormatter.php => DownloadPresenter.php} | 2 +- .../FindHost/FindHostPresenterStub.php | 22 ------------------- .../FindMetaServicePresenterStub.php | 21 ------------------ .../FindService/FindServicePresenterStub.php | 21 ------------------ .../FindHostCategoryPresenterStub.php | 21 ------------------ .../FindServiceCategoryPresenterStub.php | 21 ------------------ .../LoginSession/LoginPresenterStub.php | 21 ------------------ 8 files changed, 2 insertions(+), 129 deletions(-) rename src/Core/Infrastructure/Common/Presenter/{DownloadFormatter.php => DownloadPresenter.php} (97%) diff --git a/config/packages/Centreon.yaml b/config/packages/Centreon.yaml index b0671d34766..0bfa8e3b86b 100644 --- a/config/packages/Centreon.yaml +++ b/config/packages/Centreon.yaml @@ -95,7 +95,7 @@ services: presenter.download.csv: class: Core\Infrastructure\Common\Presenter\DownloadPresenter - arguments: ['@Core\Infrastructure\Common\Presenter\CsvPresenter'] + arguments: ['@Core\Infrastructure\Common\Presenter\CsvFormatter'] Core\Application\RealTime\UseCase\FindPerformanceMetrics\FindPerformanceMetricPresenterInterface: class: Core\Infrastructure\RealTime\Api\DownloadPerformanceMetrics\DownloadPerformanceMetricsPresenter diff --git a/src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php b/src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php similarity index 97% rename from src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php rename to src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php index 66bd6110396..a9ac4076acd 100644 --- a/src/Core/Infrastructure/Common/Presenter/DownloadFormatter.php +++ b/src/Core/Infrastructure/Common/Presenter/DownloadPresenter.php @@ -25,7 +25,7 @@ use Symfony\Component\HttpFoundation\Response; -class DownloadFormatter extends AbstractFormatter implements PresenterFormatterInterface, DownloadInterface +class DownloadPresenter extends AbstractFormatter implements PresenterFormatterInterface, DownloadInterface { private const CSV_FILE_EXTENSION = 'csv'; private const JSON_FILE_EXTENSION = 'json'; diff --git a/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostPresenterStub.php b/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostPresenterStub.php index 0a6b015991a..9464020e904 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostPresenterStub.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostPresenterStub.php @@ -35,11 +35,6 @@ class FindHostPresenterStub extends AbstractPresenter implements FindHostPresent */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * constructor */ @@ -63,21 +58,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - * @return void - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } } diff --git a/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServicePresenterStub.php b/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServicePresenterStub.php index d5320f60485..0c3df0efef5 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServicePresenterStub.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindMetaService/FindMetaServicePresenterStub.php @@ -35,11 +35,6 @@ class FindMetaServicePresenterStub extends AbstractPresenter implements FindMeta */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * constructor */ @@ -62,20 +57,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } } diff --git a/tests/php/Core/Application/RealTime/UseCase/FindService/FindServicePresenterStub.php b/tests/php/Core/Application/RealTime/UseCase/FindService/FindServicePresenterStub.php index 2fb0a2357c0..aad6dfb7969 100644 --- a/tests/php/Core/Application/RealTime/UseCase/FindService/FindServicePresenterStub.php +++ b/tests/php/Core/Application/RealTime/UseCase/FindService/FindServicePresenterStub.php @@ -35,11 +35,6 @@ class FindServicePresenterStub extends AbstractPresenter implements FindServiceP */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * constructor */ @@ -62,20 +57,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } } diff --git a/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php b/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php index 54beebf2723..ee886b548a7 100644 --- a/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php +++ b/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php @@ -35,11 +35,6 @@ class FindHostCategoryPresenterStub extends AbstractPresenter implements FindHos */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - public function __construct() { } @@ -59,20 +54,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } } diff --git a/tests/php/Core/Category/RealTime/Application/UseCase/FindServiceCategory/FindServiceCategoryPresenterStub.php b/tests/php/Core/Category/RealTime/Application/UseCase/FindServiceCategory/FindServiceCategoryPresenterStub.php index 995a7991581..8b66ed6c7ee 100644 --- a/tests/php/Core/Category/RealTime/Application/UseCase/FindServiceCategory/FindServiceCategoryPresenterStub.php +++ b/tests/php/Core/Category/RealTime/Application/UseCase/FindServiceCategory/FindServiceCategoryPresenterStub.php @@ -35,11 +35,6 @@ class FindServiceCategoryPresenterStub extends AbstractPresenter implements Find */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * constructor */ @@ -62,20 +57,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } } diff --git a/tests/php/Core/Security/Authentication/Application/UseCase/LoginSession/LoginPresenterStub.php b/tests/php/Core/Security/Authentication/Application/UseCase/LoginSession/LoginPresenterStub.php index 9337205a324..a5d6d48431c 100644 --- a/tests/php/Core/Security/Authentication/Application/UseCase/LoginSession/LoginPresenterStub.php +++ b/tests/php/Core/Security/Authentication/Application/UseCase/LoginSession/LoginPresenterStub.php @@ -34,11 +34,6 @@ class LoginPresenterStub extends AbstractPresenter implements LoginPresenterInte */ public $response; - /** - * @var ResponseStatusInterface|null - */ - protected $responseStatus; - /** * constructor */ @@ -61,20 +56,4 @@ public function present(mixed $response): void { $this->response = $response; } - - /** - * @param ResponseStatusInterface|null $responseStatus - */ - public function setResponseStatus(?ResponseStatusInterface $responseStatus): void - { - $this->responseStatus = $responseStatus; - } - - /** - * @return ResponseStatusInterface|null - */ - public function getResponseStatus(): ?ResponseStatusInterface - { - return $this->responseStatus; - } }