From 87d3b5a4b0facdf686cbb7738c18b156b462d5bc Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Wed, 21 Jul 2021 10:04:46 +0300 Subject: [PATCH 01/22] Downgrade from php8 to php7.4 using rector --- composer.json | 2 +- composer.lock | 126 +++++++++++++++++- src/Api/Dto/JsonDeserializableInterface.php | 2 +- src/Dto/Messaging/Http/Inner/Command.php | 17 ++- .../Messaging/Http/Inner/OutboxMessage.php | 5 +- src/Dto/Messaging/Http/OutboxResponse.php | 5 +- src/Dto/Onboard/Authentication.php | 6 +- src/Dto/Onboard/AuthorizationToken.php | 6 +- src/Dto/Onboard/ConnectionCriteria.php | 6 +- src/Dto/Onboard/OnboardResponse.php | 6 +- src/Dto/Onboard/VerificationResponse.php | 18 ++- src/Service/Common/DecodeMessageService.php | 2 +- 12 files changed, 181 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 8407b24..6338d11 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } }, "require": { - "php": "8.*", + "php": ">=7.4", "ext-dom": "*", "ext-bcmath": "*", "ext-mbstring": "*", diff --git a/composer.lock b/composer.lock index f53c48b..9342841 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4d3010e17657cc033ffc1c3d877addea", + "content-hash": "f060f5bb225da051cdda6070ece8c6fe", "packages": [ { "name": "google/protobuf", @@ -1177,6 +1177,70 @@ }, "time": "2020-12-19T10:15:11+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.91", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "8226701cd228a0d63c2df995de7ab6070c69ac6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8226701cd228a0d63c2df995de7ab6070c69ac6a", + "reference": "8226701cd228a0d63c2df995de7ab6070c69ac6a", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.91" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-07-04T15:31:48+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.5", @@ -1692,6 +1756,65 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "rector/rector", + "version": "0.11.36", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "0c1004ad176273c2249a1384ffb160167f5f2199" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/0c1004ad176273c2249a1384ffb160167f5f2199", + "reference": "0c1004ad176273c2249a1384ffb160167f5f2199", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0", + "phpstan/phpstan": "0.12.91" + }, + "conflict": { + "phpstan/phpdoc-parser": "<=0.5.3", + "phpstan/phpstan": "<=0.12.82", + "rector/rector-cakephp": "*", + "rector/rector-doctrine": "*", + "rector/rector-nette": "*", + "rector/rector-phpunit": "*", + "rector/rector-prefixed": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.10-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Prefixed and PHP 7.1 downgraded version of rector/rector", + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/0.11.36" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2021-07-10T19:27:51+00:00" + }, { "name": "sebastian/cli-parser", "version": "1.0.1", @@ -2845,6 +2968,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { + "php": ">=7.4", "ext-dom": "*", "ext-bcmath": "*", "ext-mbstring": "*", diff --git a/src/Api/Dto/JsonDeserializableInterface.php b/src/Api/Dto/JsonDeserializableInterface.php index 9fa0e4b..0d2085b 100644 --- a/src/Api/Dto/JsonDeserializableInterface.php +++ b/src/Api/Dto/JsonDeserializableInterface.php @@ -16,6 +16,6 @@ interface JsonDeserializableInterface * @return self New onboard response created from data array * @throws JsonException Could be thrown if th entity can not be deserialized. */ - public function jsonDeserialize(array|string $jsonData): self; + public function jsonDeserialize($jsonData); } } \ No newline at end of file diff --git a/src/Dto/Messaging/Http/Inner/Command.php b/src/Dto/Messaging/Http/Inner/Command.php index 50822ee..522155e 100644 --- a/src/Dto/Messaging/Http/Inner/Command.php +++ b/src/Dto/Messaging/Http/Inner/Command.php @@ -16,7 +16,10 @@ class Command implements JsonDeserializableInterface private string $message; - public function jsonDeserialize(array|string $jsonData): JsonDeserializableInterface + /** + * @param mixed[]|string $jsonData + */ + public function jsonDeserialize($jsonData): JsonDeserializableInterface { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); @@ -24,10 +27,14 @@ public function jsonDeserialize(array|string $jsonData): JsonDeserializableInter $decodedJsonDataArray = $jsonData; } foreach ($decodedJsonDataArray as $fieldName => $fieldValue) { - $this->message = match ($fieldName) { - self::MESSAGE => $fieldValue, - default => throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA), - }; + switch ($fieldName) { + case self::MESSAGE: + $this->message = $fieldValue; + break; + default: + $this->message = throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); + break; + } } return $this; } diff --git a/src/Dto/Messaging/Http/Inner/OutboxMessage.php b/src/Dto/Messaging/Http/Inner/OutboxMessage.php index 168d712..af7d6b8 100644 --- a/src/Dto/Messaging/Http/Inner/OutboxMessage.php +++ b/src/Dto/Messaging/Http/Inner/OutboxMessage.php @@ -20,7 +20,10 @@ class OutboxMessage implements JsonDeserializableInterface private string $sensorAlternateId; private Command $command; - public function jsonDeserialize(array|string $jsonData): JsonDeserializableInterface + /** + * @param mixed[]|string $jsonData + */ + public function jsonDeserialize($jsonData): JsonDeserializableInterface { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Messaging/Http/OutboxResponse.php b/src/Dto/Messaging/Http/OutboxResponse.php index 9fedf6a..73dfc80 100644 --- a/src/Dto/Messaging/Http/OutboxResponse.php +++ b/src/Dto/Messaging/Http/OutboxResponse.php @@ -14,7 +14,10 @@ class OutboxResponse implements JsonDeserializableInterface private string $statusCode; private array $messages; - public function jsonDeserialize(array|string $jsonData): JsonDeserializableInterface + /** + * @param mixed[]|string $jsonData + */ + public function jsonDeserialize($jsonData): JsonDeserializableInterface { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Onboard/Authentication.php b/src/Dto/Onboard/Authentication.php index 945f0d3..7f7e7b6 100644 --- a/src/Dto/Onboard/Authentication.php +++ b/src/Dto/Onboard/Authentication.php @@ -63,7 +63,11 @@ public function setCertificate(string $certificate): void $this->certificate = $certificate; } - public function jsonDeserialize(string|array $jsonData): self + /** + * @param string|mixed[] $jsonData + * @return $this + */ + public function jsonDeserialize($jsonData) { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Onboard/AuthorizationToken.php b/src/Dto/Onboard/AuthorizationToken.php index 1abcaa6..0adfed2 100644 --- a/src/Dto/Onboard/AuthorizationToken.php +++ b/src/Dto/Onboard/AuthorizationToken.php @@ -50,7 +50,11 @@ public function setExpires(string $expires): void $this->expires = $expires; } - public function jsonDeserialize(string|array $jsonData): self + /** + * @param string|mixed[] $jsonData + * @return $this + */ + public function jsonDeserialize($jsonData) { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Onboard/ConnectionCriteria.php b/src/Dto/Onboard/ConnectionCriteria.php index 87f3cec..801d267 100644 --- a/src/Dto/Onboard/ConnectionCriteria.php +++ b/src/Dto/Onboard/ConnectionCriteria.php @@ -102,7 +102,11 @@ public function setPort(string $port): void $this->port = $port; } - public function jsonDeserialize(string|array $jsonData): self + /** + * @param string|mixed[] $jsonData + * @return $this + */ + public function jsonDeserialize($jsonData) { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Onboard/OnboardResponse.php b/src/Dto/Onboard/OnboardResponse.php index 9a7cef2..bc569c4 100644 --- a/src/Dto/Onboard/OnboardResponse.php +++ b/src/Dto/Onboard/OnboardResponse.php @@ -93,7 +93,11 @@ public function setSensorAlternateId(string $sensorAlternateId): void $this->sensorAlternateId = $sensorAlternateId; } - public function jsonDeserialize(array|string $jsonData): self + /** + * @param mixed[]|string $jsonData + * @return $this + */ + public function jsonDeserialize($jsonData) { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); diff --git a/src/Dto/Onboard/VerificationResponse.php b/src/Dto/Onboard/VerificationResponse.php index 8f38447..57f1e03 100644 --- a/src/Dto/Onboard/VerificationResponse.php +++ b/src/Dto/Onboard/VerificationResponse.php @@ -40,7 +40,11 @@ public function setAccountId(string $accountId): void $this->accountId = $accountId; } - public function jsonDeserialize(array|string $jsonData): self + /** + * @param mixed[]|string $jsonData + * @return $this + */ + public function jsonDeserialize($jsonData) { if (is_string($jsonData)) { $decodedJsonDataArray = json_decode($jsonData, true); @@ -48,10 +52,14 @@ public function jsonDeserialize(array|string $jsonData): self $decodedJsonDataArray = $jsonData; } foreach ($decodedJsonDataArray as $fieldName => $fieldValue) { - $this->accountId = match ($fieldName) { - self::ACCOUNT_ID => $fieldValue, - default => throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA), - }; + switch ($fieldName) { + case self::ACCOUNT_ID: + $this->accountId = $fieldValue; + break; + default: + $this->accountId = throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); + break; + } } return $this; } diff --git a/src/Service/Common/DecodeMessageService.php b/src/Service/Common/DecodeMessageService.php index b77f1a5..6455911 100644 --- a/src/Service/Common/DecodeMessageService.php +++ b/src/Service/Common/DecodeMessageService.php @@ -61,7 +61,7 @@ public function decodeResponse(string $message): DecodedMessage * @throws Exception * @noinspection PhpMixedReturnTypeCanBeReducedInspection */ - public function decodeDetails(Any $details): mixed + public function decodeDetails(Any $details) { switch ($details->getTypeUrl()) { case TypeUrlService::getTypeUrl(Messages::class): From 348f700492e58cff175a7207494ac4245de65ea5 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Wed, 21 Jul 2021 10:43:56 +0300 Subject: [PATCH 02/22] Removed "Pure" php annotations --- src/Api/Exceptions/AuthorizationException.php | 2 +- src/Api/Exceptions/BusinessException.php | 2 +- src/Api/Exceptions/DecodeMessageException.php | 2 +- src/Api/Exceptions/MessagingException.php | 2 +- src/Api/Exceptions/OnboardException.php | 2 +- src/Api/Exceptions/OutboxException.php | 2 +- src/Api/Exceptions/RevokeException.php | 2 +- src/Api/Exceptions/SignatureException.php | 2 +- src/Api/Exceptions/ValidationException.php | 2 +- src/Api/Exceptions/VerificationException.php | 2 +- src/Service/Cloud/CloudOffboardService.php | 2 +- src/Service/Cloud/CloudOnboardService.php | 2 +- src/Service/Common/UtcDataService.php | 2 +- src/Service/Common/UuidService.php | 2 +- src/Service/Messaging/CapabilityService.php | 2 +- src/Service/Messaging/FeedConfirmService.php | 2 +- src/Service/Messaging/FeedDeleteService.php | 2 +- src/Service/Messaging/ListEndpointsService.php | 2 +- src/Service/Messaging/QueryHeadersService.php | 2 +- src/Service/Messaging/QueryMessagesService.php | 2 +- src/Service/Messaging/SubscriptionService.php | 2 +- tests/Helper/MqttClient.php | 4 ++-- 22 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Api/Exceptions/AuthorizationException.php b/src/Api/Exceptions/AuthorizationException.php index dff389c..0b01b8b 100644 --- a/src/Api/Exceptions/AuthorizationException.php +++ b/src/Api/Exceptions/AuthorizationException.php @@ -17,7 +17,7 @@ class AuthorizationException extends BusinessException * @param int $code The code. * @param Exception|null $previous Previous exception. */ - #[Pure] public function __construct(string $message, int $code, Exception $previous = null) + public function __construct(string $message, int $code, Exception $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Api/Exceptions/BusinessException.php b/src/Api/Exceptions/BusinessException.php index 858dcbc..e3636db 100644 --- a/src/Api/Exceptions/BusinessException.php +++ b/src/Api/Exceptions/BusinessException.php @@ -17,7 +17,7 @@ class BusinessException extends Exception * @param int $code Internal code. * @param Exception|null $previous Previous exception. */ - #[Pure] public function __construct(string $message, int $code, Exception $previous = null) + public function __construct(string $message, int $code, Exception $previous = null) { parent::__construct($message, $code, $previous); diff --git a/src/Api/Exceptions/DecodeMessageException.php b/src/Api/Exceptions/DecodeMessageException.php index 4b00433..f6b2c07 100644 --- a/src/Api/Exceptions/DecodeMessageException.php +++ b/src/Api/Exceptions/DecodeMessageException.php @@ -17,7 +17,7 @@ class DecodeMessageException extends BusinessException * @param int $code The code. * @param Exception|null $previous Previous exception. */ - #[Pure] public function __construct(string $message, int $code, Exception $previous = null) + public function __construct(string $message, int $code, Exception $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Api/Exceptions/MessagingException.php b/src/Api/Exceptions/MessagingException.php index 905365f..81c0835 100644 --- a/src/Api/Exceptions/MessagingException.php +++ b/src/Api/Exceptions/MessagingException.php @@ -16,7 +16,7 @@ class MessagingException extends BusinessException * @param string $message The message. * @param int $code The code. */ - #[Pure] public function __construct(string $message, int $code) + public function __construct(string $message, int $code) { parent::__construct($message, $code); } diff --git a/src/Api/Exceptions/OnboardException.php b/src/Api/Exceptions/OnboardException.php index 00ca5b2..93e9a72 100644 --- a/src/Api/Exceptions/OnboardException.php +++ b/src/Api/Exceptions/OnboardException.php @@ -16,7 +16,7 @@ class OnboardException extends BusinessException * @param string $message The message. * @param int $code The code. */ - #[Pure] public function __construct(string $message, int $code) + public function __construct(string $message, int $code) { parent::__construct($message, $code); } diff --git a/src/Api/Exceptions/OutboxException.php b/src/Api/Exceptions/OutboxException.php index 5b033bc..b69ef68 100644 --- a/src/Api/Exceptions/OutboxException.php +++ b/src/Api/Exceptions/OutboxException.php @@ -16,7 +16,7 @@ class OutboxException extends BusinessException * @param string $message The message. * @param int $code The code. */ - #[Pure] public function __construct(string $message, int $code) + public function __construct(string $message, int $code) { parent::__construct($message, $code); } diff --git a/src/Api/Exceptions/RevokeException.php b/src/Api/Exceptions/RevokeException.php index f341efa..d5604ef 100644 --- a/src/Api/Exceptions/RevokeException.php +++ b/src/Api/Exceptions/RevokeException.php @@ -16,7 +16,7 @@ class RevokeException extends BusinessException * @param string $message The message. * @param int $code The code. */ - #[Pure] public function __construct(string $message, int $code) + public function __construct(string $message, int $code) { parent::__construct($message, $code); } diff --git a/src/Api/Exceptions/SignatureException.php b/src/Api/Exceptions/SignatureException.php index c45786d..d1c11bb 100644 --- a/src/Api/Exceptions/SignatureException.php +++ b/src/Api/Exceptions/SignatureException.php @@ -17,7 +17,7 @@ class SignatureException extends BusinessException * @param int $code The code. * @param Exception|null $previous */ - #[Pure] public function __construct(string $message, int $code, Exception $previous = null) + public function __construct(string $message, int $code, Exception $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Api/Exceptions/ValidationException.php b/src/Api/Exceptions/ValidationException.php index 87ea10c..8cd018f 100644 --- a/src/Api/Exceptions/ValidationException.php +++ b/src/Api/Exceptions/ValidationException.php @@ -15,7 +15,7 @@ class ValidationException extends BusinessException * Constructor. * @param string $invalidParameter Invalid parameter */ - #[Pure] public function __construct(string $invalidParameter) + public function __construct(string $invalidParameter) { parent::__construct("Parameters passed are not valid. The following parameter is invalid >>> $invalidParameter", ErrorCodes::PARAMETER_INVALID); } diff --git a/src/Api/Exceptions/VerificationException.php b/src/Api/Exceptions/VerificationException.php index d946063..035d5fc 100644 --- a/src/Api/Exceptions/VerificationException.php +++ b/src/Api/Exceptions/VerificationException.php @@ -16,7 +16,7 @@ class VerificationException extends BusinessException * @param string $message The message. * @param int $code The code. */ - #[Pure] public function __construct(string $message, int $code) + public function __construct(string $message, int $code) { parent::__construct($message, $code); } diff --git a/src/Service/Cloud/CloudOffboardService.php b/src/Service/Cloud/CloudOffboardService.php index f0946d2..cff3204 100644 --- a/src/Service/Cloud/CloudOffboardService.php +++ b/src/Service/Cloud/CloudOffboardService.php @@ -33,7 +33,7 @@ class CloudOffboardService implements MessagingServiceInterface, EncodeMessageSe * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Cloud/CloudOnboardService.php b/src/Service/Cloud/CloudOnboardService.php index 4bc4308..4cde326 100644 --- a/src/Service/Cloud/CloudOnboardService.php +++ b/src/Service/Cloud/CloudOnboardService.php @@ -33,7 +33,7 @@ class CloudOnboardService implements MessagingServiceInterface, EncodeMessageSer * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Common/UtcDataService.php b/src/Service/Common/UtcDataService.php index ea923d4..51ccdec 100644 --- a/src/Service/Common/UtcDataService.php +++ b/src/Service/Common/UtcDataService.php @@ -30,7 +30,7 @@ public static function now(): string * @param int $offset . * @return string The current time zone. */ - #[Pure] public static function timeZone(int $offset): string + public static function timeZone(int $offset): string { return sprintf("%s%02d:00", ($offset >= 0) ? '+' : '-', abs($offset / 3600)); } diff --git a/src/Service/Common/UuidService.php b/src/Service/Common/UuidService.php index e54b1cb..5989aeb 100644 --- a/src/Service/Common/UuidService.php +++ b/src/Service/Common/UuidService.php @@ -15,7 +15,7 @@ class UuidService * Generate a new UUID. * @return string . */ - #[Pure] public static function newUuid(): string + public static function newUuid(): string { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), diff --git a/src/Service/Messaging/CapabilityService.php b/src/Service/Messaging/CapabilityService.php index 3274b8f..5e6b39f 100644 --- a/src/Service/Messaging/CapabilityService.php +++ b/src/Service/Messaging/CapabilityService.php @@ -33,7 +33,7 @@ class CapabilityService implements MessagingServiceInterface, EncodeMessageServi * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/FeedConfirmService.php b/src/Service/Messaging/FeedConfirmService.php index 4752b61..2c874be 100644 --- a/src/Service/Messaging/FeedConfirmService.php +++ b/src/Service/Messaging/FeedConfirmService.php @@ -33,7 +33,7 @@ class FeedConfirmService implements MessagingServiceInterface, EncodeMessageServ * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/FeedDeleteService.php b/src/Service/Messaging/FeedDeleteService.php index 7e7b7ac..24c574b 100644 --- a/src/Service/Messaging/FeedDeleteService.php +++ b/src/Service/Messaging/FeedDeleteService.php @@ -35,7 +35,7 @@ class FeedDeleteService implements MessagingServiceInterface, EncodeMessageServi * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/ListEndpointsService.php b/src/Service/Messaging/ListEndpointsService.php index c5478fd..a5f3ebf 100644 --- a/src/Service/Messaging/ListEndpointsService.php +++ b/src/Service/Messaging/ListEndpointsService.php @@ -33,7 +33,7 @@ class ListEndpointsService implements MessagingServiceInterface, EncodeMessageSe * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/QueryHeadersService.php b/src/Service/Messaging/QueryHeadersService.php index a8f26eb..9fd3c02 100644 --- a/src/Service/Messaging/QueryHeadersService.php +++ b/src/Service/Messaging/QueryHeadersService.php @@ -34,7 +34,7 @@ class QueryHeadersService implements MessagingServiceInterface, EncodeMessageSer * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/QueryMessagesService.php b/src/Service/Messaging/QueryMessagesService.php index dd576cd..c7c503a 100644 --- a/src/Service/Messaging/QueryMessagesService.php +++ b/src/Service/Messaging/QueryMessagesService.php @@ -34,7 +34,7 @@ class QueryMessagesService implements MessagingServiceInterface, EncodeMessageSe * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/src/Service/Messaging/SubscriptionService.php b/src/Service/Messaging/SubscriptionService.php index cdcc83e..1584236 100644 --- a/src/Service/Messaging/SubscriptionService.php +++ b/src/Service/Messaging/SubscriptionService.php @@ -33,7 +33,7 @@ class SubscriptionService implements MessagingServiceInterface, EncodeMessageSer * Constructor. * @param MessagingServiceInterface $messagingService Service for message sending. */ - #[Pure] public function __construct(MessagingServiceInterface $messagingService) + public function __construct(MessagingServiceInterface $messagingService) { $this->messagingService = $messagingService; } diff --git a/tests/Helper/MqttClient.php b/tests/Helper/MqttClient.php index 1f019af..4dacdfb 100644 --- a/tests/Helper/MqttClient.php +++ b/tests/Helper/MqttClient.php @@ -36,7 +36,7 @@ class MqttClient implements MqttClientInterface * @param PhpMqttClient $mqttClient The PhpMqtt client. * @param LoggerInterface|null $logger The logger used for logging. */ - #[Pure] public function __construct(PhpMqttClient $mqttClient, ?LoggerInterface $logger = null) + public function __construct(PhpMqttClient $mqttClient, ?LoggerInterface $logger = null) { $this->mqttClient = $mqttClient; $this->logger = $logger; @@ -93,7 +93,7 @@ public function unsubscribe(string $topic): void /** * @inheritDoc */ - #[Pure] public function isConnected(): bool + public function isConnected(): bool { return $this->mqttClient->isConnected(); } From 23356853c456405f57a35faf102155228bc2e0f7 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Wed, 21 Jul 2021 12:29:11 +0300 Subject: [PATCH 03/22] Removed "ArrayShape" php annotations --- src/Dto/Messaging/Inner/Message.php | 1 - src/Dto/Onboard/Authentication.php | 1 - src/Dto/Onboard/ConnectionCriteria.php | 1 - src/Dto/Onboard/OnboardResponse.php | 2 -- src/Dto/Onboard/VerificationResponse.php | 1 - src/Dto/Requests/MessageRequest.php | 1 - src/Dto/Requests/OnboardRequest.php | 1 - src/Dto/Requests/RevokeRequest.php | 1 - 8 files changed, 9 deletions(-) diff --git a/src/Dto/Messaging/Inner/Message.php b/src/Dto/Messaging/Inner/Message.php index 26c5eab..e616475 100644 --- a/src/Dto/Messaging/Inner/Message.php +++ b/src/Dto/Messaging/Inner/Message.php @@ -37,7 +37,6 @@ public function setTimestamp(string $timestamp): void $this->timestamp = $timestamp; } - #[ArrayShape([self::MESSAGE => "string", self::TIMESTAMP => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Onboard/Authentication.php b/src/Dto/Onboard/Authentication.php index 7f7e7b6..94b6497 100644 --- a/src/Dto/Onboard/Authentication.php +++ b/src/Dto/Onboard/Authentication.php @@ -23,7 +23,6 @@ class Authentication implements JsonSerializable, JsonDeserializableInterface private string $certificate; - #[ArrayShape([self::TYPE => "string", self::SECRET => "string", self::CERTIFICATE => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Onboard/ConnectionCriteria.php b/src/Dto/Onboard/ConnectionCriteria.php index 801d267..dd0bd4f 100644 --- a/src/Dto/Onboard/ConnectionCriteria.php +++ b/src/Dto/Onboard/ConnectionCriteria.php @@ -28,7 +28,6 @@ class ConnectionCriteria implements JsonSerializable, JsonDeserializableInterfac private string $port; private string $clientId; - #[ArrayShape([self::CLIENT_ID => "string", self::COMMANDS => "string", self::GATEWAY_ID => "string", self::HOST => "string", self::MEASURES => "string", self::PORT => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Onboard/OnboardResponse.php b/src/Dto/Onboard/OnboardResponse.php index bc569c4..2ebc5ba 100644 --- a/src/Dto/Onboard/OnboardResponse.php +++ b/src/Dto/Onboard/OnboardResponse.php @@ -30,8 +30,6 @@ class OnboardResponse implements JsonSerializable, JsonDeserializableInterface * Serializes the object data to a simple array * @return array Array with object data. */ - #[ArrayShape([self::AUTHENTICATION => Authentication::class, self::CAPABILITY_ALTERNATE_ID => "string", - self::CONNECTION_CRITERIA => ConnectionCriteria::class, self::DEVICE_ALTERNATE_ID => "string", self::SENSOR_ALTERNATE_ID => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Onboard/VerificationResponse.php b/src/Dto/Onboard/VerificationResponse.php index 57f1e03..dc84796 100644 --- a/src/Dto/Onboard/VerificationResponse.php +++ b/src/Dto/Onboard/VerificationResponse.php @@ -22,7 +22,6 @@ class VerificationResponse implements JsonSerializable, JsonDeserializableInterf * Serializes the object data to a simple array * @return array Array with object data. */ - #[ArrayShape([self::ACCOUNT_ID => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Requests/MessageRequest.php b/src/Dto/Requests/MessageRequest.php index abad444..71ac83c 100644 --- a/src/Dto/Requests/MessageRequest.php +++ b/src/Dto/Requests/MessageRequest.php @@ -49,7 +49,6 @@ public function setMessages(array $messages): void $this->messages = $messages; } - #[ArrayShape([self::SENSOR_ALTERNATE_ID => "string", self::CAPABILITY_ALTERNATE_ID => "string", self::MESSAGES => "array"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Requests/OnboardRequest.php b/src/Dto/Requests/OnboardRequest.php index cf231be..60a7b3d 100644 --- a/src/Dto/Requests/OnboardRequest.php +++ b/src/Dto/Requests/OnboardRequest.php @@ -97,7 +97,6 @@ public function setCertificateType(string $certificateType): void $this->certificateType = $certificateType; } - #[ArrayShape([self::ID => "string", self::APPLICATION_ID => "string", self::CERTIFICATION_VERSION_ID => "string", self::GATEWAY_ID => "string", self::UTC_TIMESTAMP => "string", self::TIME_ZONE => "string", self::CERTIFICATE_TYPE => "string"])] public function jsonSerialize(): array { return [ diff --git a/src/Dto/Requests/RevokeRequest.php b/src/Dto/Requests/RevokeRequest.php index 3e66b67..5cd5c43 100644 --- a/src/Dto/Requests/RevokeRequest.php +++ b/src/Dto/Requests/RevokeRequest.php @@ -21,7 +21,6 @@ class RevokeRequest implements JsonSerializable private string $utcTimestamp; private string $timeZone; - #[ArrayShape([self::ACCOUNT_ID => "string", self::ENDPOINT_IDS => "array", self::UTC_TIMESTAMP => "string", self::TIME_ZONE => "string"])] public function jsonSerialize(): array { return [ From d662d0b9324e20ce22d5adeb2f178ca064ed5dda Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Thu, 22 Jul 2021 16:12:27 +0300 Subject: [PATCH 04/22] Update composer.lock --- composer.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 9342841..fe2a987 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f060f5bb225da051cdda6070ece8c6fe", + "content-hash": "f385eae3358f893a5b226f4d4681f98b", "packages": [ { "name": "google/protobuf", @@ -2668,6 +2668,7 @@ "type": "github" } ], + "abandoned": true, "time": "2020-09-28T06:45:17+00:00" }, { From 81e48114177c87938b49d5a6e652f25abbaa9722 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Thu, 22 Jul 2021 16:25:38 +0300 Subject: [PATCH 05/22] Removed throw expression --- src/Dto/Messaging/Http/Inner/Command.php | 2 +- src/Dto/Onboard/VerificationResponse.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dto/Messaging/Http/Inner/Command.php b/src/Dto/Messaging/Http/Inner/Command.php index 522155e..0356fd2 100644 --- a/src/Dto/Messaging/Http/Inner/Command.php +++ b/src/Dto/Messaging/Http/Inner/Command.php @@ -32,7 +32,7 @@ public function jsonDeserialize($jsonData): JsonDeserializableInterface $this->message = $fieldValue; break; default: - $this->message = throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); + throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); break; } } diff --git a/src/Dto/Onboard/VerificationResponse.php b/src/Dto/Onboard/VerificationResponse.php index dc84796..7694708 100644 --- a/src/Dto/Onboard/VerificationResponse.php +++ b/src/Dto/Onboard/VerificationResponse.php @@ -56,7 +56,7 @@ public function jsonDeserialize($jsonData) $this->accountId = $fieldValue; break; default: - $this->accountId = throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); + throw new JsonException("Unknown field '$fieldName' for class '" . get_class($this) . "'.", ErrorCodes::UNKNOWN_FIELD_IN_JSON_DATA); break; } } From b4a68c9ee91c835614db3eb35308f28140762440 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Thu, 22 Jul 2021 16:28:53 +0300 Subject: [PATCH 06/22] Removed pure --- src/Api/Exceptions/AuthorizationException.php | 1 - src/Api/Exceptions/BusinessException.php | 1 - src/Api/Exceptions/DecodeMessageException.php | 1 - src/Api/Exceptions/MessagingException.php | 1 - src/Api/Exceptions/OnboardException.php | 1 - src/Api/Exceptions/OutboxException.php | 1 - src/Api/Exceptions/RevokeException.php | 1 - src/Api/Exceptions/SignatureException.php | 1 - src/Api/Exceptions/ValidationException.php | 1 - src/Api/Exceptions/VerificationException.php | 1 - src/Service/Cloud/CloudOffboardService.php | 1 - src/Service/Cloud/CloudOnboardService.php | 1 - src/Service/Common/UtcDataService.php | 1 - src/Service/Common/UuidService.php | 1 - src/Service/Messaging/CapabilityService.php | 1 - src/Service/Messaging/FeedConfirmService.php | 1 - src/Service/Messaging/FeedDeleteService.php | 1 - src/Service/Messaging/ListEndpointsService.php | 1 - src/Service/Messaging/QueryHeadersService.php | 1 - src/Service/Messaging/QueryMessagesService.php | 1 - src/Service/Messaging/SubscriptionService.php | 1 - 21 files changed, 21 deletions(-) diff --git a/src/Api/Exceptions/AuthorizationException.php b/src/Api/Exceptions/AuthorizationException.php index 0b01b8b..d3b3c41 100644 --- a/src/Api/Exceptions/AuthorizationException.php +++ b/src/Api/Exceptions/AuthorizationException.php @@ -3,7 +3,6 @@ namespace App\Api\Exceptions { use Exception; - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error during the signature creation process. diff --git a/src/Api/Exceptions/BusinessException.php b/src/Api/Exceptions/BusinessException.php index e3636db..387d5d4 100644 --- a/src/Api/Exceptions/BusinessException.php +++ b/src/Api/Exceptions/BusinessException.php @@ -3,7 +3,6 @@ namespace App\Api\Exceptions { use Exception; - use JetBrains\PhpStorm\Pure; /** * Wrapper for all internal exceptions. diff --git a/src/Api/Exceptions/DecodeMessageException.php b/src/Api/Exceptions/DecodeMessageException.php index f6b2c07..498982a 100644 --- a/src/Api/Exceptions/DecodeMessageException.php +++ b/src/Api/Exceptions/DecodeMessageException.php @@ -3,7 +3,6 @@ namespace App\Api\Exceptions { use Exception; - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error while decoding a message from the AR. diff --git a/src/Api/Exceptions/MessagingException.php b/src/Api/Exceptions/MessagingException.php index 81c0835..4cdad05 100644 --- a/src/Api/Exceptions/MessagingException.php +++ b/src/Api/Exceptions/MessagingException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Generic messaging exception. diff --git a/src/Api/Exceptions/OnboardException.php b/src/Api/Exceptions/OnboardException.php index 93e9a72..12646d5 100644 --- a/src/Api/Exceptions/OnboardException.php +++ b/src/Api/Exceptions/OnboardException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error during the onboard process. diff --git a/src/Api/Exceptions/OutboxException.php b/src/Api/Exceptions/OutboxException.php index b69ef68..14b6313 100644 --- a/src/Api/Exceptions/OutboxException.php +++ b/src/Api/Exceptions/OutboxException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is any problem during the interaction with the outbox. diff --git a/src/Api/Exceptions/RevokeException.php b/src/Api/Exceptions/RevokeException.php index d5604ef..a66345a 100644 --- a/src/Api/Exceptions/RevokeException.php +++ b/src/Api/Exceptions/RevokeException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error during the revoke endpoint process. diff --git a/src/Api/Exceptions/SignatureException.php b/src/Api/Exceptions/SignatureException.php index d1c11bb..97bfbf5 100644 --- a/src/Api/Exceptions/SignatureException.php +++ b/src/Api/Exceptions/SignatureException.php @@ -3,7 +3,6 @@ namespace App\Api\Exceptions { use Exception; - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error during the signature creation process. diff --git a/src/Api/Exceptions/ValidationException.php b/src/Api/Exceptions/ValidationException.php index 8cd018f..1303937 100644 --- a/src/Api/Exceptions/ValidationException.php +++ b/src/Api/Exceptions/ValidationException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Will be thrown if the parameters are not valid. diff --git a/src/Api/Exceptions/VerificationException.php b/src/Api/Exceptions/VerificationException.php index 035d5fc..345a488 100644 --- a/src/Api/Exceptions/VerificationException.php +++ b/src/Api/Exceptions/VerificationException.php @@ -2,7 +2,6 @@ namespace App\Api\Exceptions { - use JetBrains\PhpStorm\Pure; /** * Will be thrown if there is an error during the verification process. diff --git a/src/Service/Cloud/CloudOffboardService.php b/src/Service/Cloud/CloudOffboardService.php index cff3204..840c278 100644 --- a/src/Service/Cloud/CloudOffboardService.php +++ b/src/Service/Cloud/CloudOffboardService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\CloudOffboardParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the cloud onboard message to the AR. diff --git a/src/Service/Cloud/CloudOnboardService.php b/src/Service/Cloud/CloudOnboardService.php index 4cde326..1154c8f 100644 --- a/src/Service/Cloud/CloudOnboardService.php +++ b/src/Service/Cloud/CloudOnboardService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\CloudOnboardParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the cloud onboard message to the AR. diff --git a/src/Service/Common/UtcDataService.php b/src/Service/Common/UtcDataService.php index 51ccdec..eeb17c5 100644 --- a/src/Service/Common/UtcDataService.php +++ b/src/Service/Common/UtcDataService.php @@ -4,7 +4,6 @@ use DateTime; use Google\Protobuf\Timestamp; - use JetBrains\PhpStorm\Pure; /** * Service to generate timestamps and hold UTC specific functions. diff --git a/src/Service/Common/UuidService.php b/src/Service/Common/UuidService.php index 5989aeb..4b84da0 100644 --- a/src/Service/Common/UuidService.php +++ b/src/Service/Common/UuidService.php @@ -2,7 +2,6 @@ namespace App\Service\Common { - use JetBrains\PhpStorm\Pure; /** * Service to generate UUIDs. diff --git a/src/Service/Messaging/CapabilityService.php b/src/Service/Messaging/CapabilityService.php index 5e6b39f..84d1ad3 100644 --- a/src/Service/Messaging/CapabilityService.php +++ b/src/Service/Messaging/CapabilityService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\CapabilityParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the capabilities to the AR. diff --git a/src/Service/Messaging/FeedConfirmService.php b/src/Service/Messaging/FeedConfirmService.php index 2c874be..9c389da 100644 --- a/src/Service/Messaging/FeedConfirmService.php +++ b/src/Service/Messaging/FeedConfirmService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\FeedConfirmParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the message confirmations to the AR. diff --git a/src/Service/Messaging/FeedDeleteService.php b/src/Service/Messaging/FeedDeleteService.php index 24c574b..71d0d73 100644 --- a/src/Service/Messaging/FeedDeleteService.php +++ b/src/Service/Messaging/FeedDeleteService.php @@ -18,7 +18,6 @@ use App\Service\Parameters\FeedDeleteParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the delete message request to the AR. diff --git a/src/Service/Messaging/ListEndpointsService.php b/src/Service/Messaging/ListEndpointsService.php index a5f3ebf..cd693fc 100644 --- a/src/Service/Messaging/ListEndpointsService.php +++ b/src/Service/Messaging/ListEndpointsService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\ListEndpointsParameters; use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the subscriptions to the AR. diff --git a/src/Service/Messaging/QueryHeadersService.php b/src/Service/Messaging/QueryHeadersService.php index 9fd3c02..6209004 100644 --- a/src/Service/Messaging/QueryHeadersService.php +++ b/src/Service/Messaging/QueryHeadersService.php @@ -17,7 +17,6 @@ use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; use App\Service\Parameters\QueryHeadersParameters; - use JetBrains\PhpStorm\Pure; /** * Service to fetch the message headers from the AR. diff --git a/src/Service/Messaging/QueryMessagesService.php b/src/Service/Messaging/QueryMessagesService.php index c7c503a..cf2e2c2 100644 --- a/src/Service/Messaging/QueryMessagesService.php +++ b/src/Service/Messaging/QueryMessagesService.php @@ -17,7 +17,6 @@ use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; use App\Service\Parameters\QueryMessagesParameters; - use JetBrains\PhpStorm\Pure; /** * Service to fetch the message headers from the AR. diff --git a/src/Service/Messaging/SubscriptionService.php b/src/Service/Messaging/SubscriptionService.php index 1584236..592baf9 100644 --- a/src/Service/Messaging/SubscriptionService.php +++ b/src/Service/Messaging/SubscriptionService.php @@ -16,7 +16,6 @@ use App\Service\Parameters\MessageHeaderParameters; use App\Service\Parameters\MessagePayloadParameters; use App\Service\Parameters\SubscriptionParameters; - use JetBrains\PhpStorm\Pure; /** * Service to send the subscriptions to the AR. From 47704c2fff9a2217638f19efa5a6704766b03d3d Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Fri, 23 Jul 2021 09:33:47 +0300 Subject: [PATCH 07/22] Added testGivenValidResponseWhenParsingTheResultThenTheSignatureVerificationShouldBeOk --- .../Onboard/AuthorizationServiceTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Service/Onboard/AuthorizationServiceTest.php b/tests/Service/Onboard/AuthorizationServiceTest.php index 1745cb8..0841861 100644 --- a/tests/Service/Onboard/AuthorizationServiceTest.php +++ b/tests/Service/Onboard/AuthorizationServiceTest.php @@ -3,6 +3,7 @@ namespace Lib\Tests\Service\Onboard { use App\Api\Exceptions\DecodeMessageException; + use App\Service\Common\SignatureService; use App\Service\Onboard\AuthorizationService; use Lib\Tests\Service\AbstractIntegrationTestForServices; @@ -107,5 +108,28 @@ public function testGivenDeclineConnectionResponseWhenParsingTheTokenThenTheAuth $this->assertNull($authorizationResult->getSignature()); $this->assertNotNull($authorizationResult->getError()); } + + public function testGivenValidResponseWhenParsingTheResultThenTheSignatureVerificationShouldBeOk() + { + $input = "state=6eab2086-0ef2-4b64-94b0-2ce620e66ece&token=eyJhY2NvdW50IjoiNWQ0N2E1MzctOTQ1NS00MTBkLWFhNmQtZmJkNjlhNWNmOTkwIiwicmVnY29kZSI6IjI2NGQwNjgzYzkiLCJleHBpcmVzIjoiMjAyMC0wMS0xNFQxMDowOTo1OS4zMTlaIn0%3D&signature=AJOFQmO4Y%2FT8DlNOcTAfpymMFiZQBpJHr4%2FUOfrHuGpzst6UA4kQraJYJtUEKSeEaQ%2FHCf4rJlUcK14ygyGAUtGkca1Y1sUAC1lVggVnECFMnVQAyTQzSnd1DEXjqI8n4Ud4LujSF6oSbiK0DWg1U8U9swwAEQ73Z0SDna7M3OEirY8zPUhGFcRij%2FrJOEFujq2rW%2Bs267z1pnp6FNq%2BoK5nbPBuH0hvCZ57Fz3HI1VadyE77o6rOAZ1HXniGqCGr%2F6v4TqAQ22MY9xhMAfUihtwQ3VLtdHsGSu1OH%2Fs71IQczOzBgeIlMAl4mchRo3l16qSU4k4awufLq7LzDSf5Q%3D%3D"; + $authorizationService = new AuthorizationService($this->getEnvironment()); + $authResult = $authorizationService->parseAuthorizationResult($input); + $agrirouterPublicKey = "-----BEGIN PUBLIC KEY-----\n". + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy8xF9661acn+iS+QS+9Y\n". + "3HvTfUVcismzbuvxHgHA7YeoOUFxyj3lkaTnXm7hzQe4wDEDgwpJSGAzxIIYSUXe\n". + "8EsWLorg5O0tRexx5SP3+kj1i83DATBJCXP7k+bAF4u2FVJphC1m2BfLxelGLjzx\n". + "VAS/v6+EwvYaT1AI9FFqW/a2o92IsVPOh9oM9eds3lBOAbH/8XrmVIeHofw+XbTH\n". + "1/7MLD6IE2+HbEeY0F96nioXArdQWXcjUQsTch+p0p9eqh23Ak4ef5oGcZhNd4yp\n". + "Y8M6ppvIMiXkgWSPJevCJjhxRJRmndY+ajYGx7CLePx7wNvxXWtkng3yh+7WiZ/Y\n". + "qwIDAQAB\n". + "-----END PUBLIC KEY-----"; + + $sigVerifyResult = SignatureService::verifySignature( + urldecode($authResult->getState()).urldecode($authResult->getToken()), + urldecode($authResult->getSignature()), + $agrirouterPublicKey + ); + $this->assertTrue($sigVerifyResult); + } } } \ No newline at end of file From d4d78edb0cc655c5d7e880dfa2969aa682e0da95 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Fri, 23 Jul 2021 13:18:31 +0300 Subject: [PATCH 08/22] Fix testGivenValidResponseWhenParsingTheResultThenTheSignatureVerificationShouldBeOk --- tests/Service/Onboard/AuthorizationServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Service/Onboard/AuthorizationServiceTest.php b/tests/Service/Onboard/AuthorizationServiceTest.php index 0841861..ff7a536 100644 --- a/tests/Service/Onboard/AuthorizationServiceTest.php +++ b/tests/Service/Onboard/AuthorizationServiceTest.php @@ -126,7 +126,7 @@ public function testGivenValidResponseWhenParsingTheResultThenTheSignatureVerifi $sigVerifyResult = SignatureService::verifySignature( urldecode($authResult->getState()).urldecode($authResult->getToken()), - urldecode($authResult->getSignature()), + base64_decode(urldecode($authResult->getSignature())), $agrirouterPublicKey ); $this->assertTrue($sigVerifyResult); From d24020a02ea1aa46868ddba54a08d223833277f1 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 26 Jul 2021 11:06:59 +0300 Subject: [PATCH 09/22] Removed usage of named parameters from tests --- .../Messaging/Mqtt/CapabilityServiceTest.php | 22 +++++++++---------- .../Mqtt/Cloud/CloudOffboardServiceTest.php | 2 +- .../Mqtt/Cloud/CloudOnboardServiceTest.php | 2 +- .../Messaging/Mqtt/FeedConfirmServiceTest.php | 4 ++-- .../Messaging/Mqtt/FeedDeleteServiceTest.php | 8 +++---- .../Mqtt/ListEndpointsServiceTest.php | 6 ++--- .../Mqtt/QueryHeadersServiceTest.php | 8 +++---- .../Mqtt/QueryMessagesServiceTest.php | 8 +++---- .../Mqtt/SubscriptionServiceTest.php | 6 ++--- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/Service/Messaging/Mqtt/CapabilityServiceTest.php b/tests/Service/Messaging/Mqtt/CapabilityServiceTest.php index 0d7eaf7..448ea06 100644 --- a/tests/Service/Messaging/Mqtt/CapabilityServiceTest.php +++ b/tests/Service/Messaging/Mqtt/CapabilityServiceTest.php @@ -128,7 +128,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $capabilityParameters->setCapabilityParameters($capabilities); $capabilityService->send($capabilityParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -188,7 +188,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $capabilityParameters->setCapabilityParameters($capabilityBuilder->build()); $capabilityService->send($capabilityParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -267,7 +267,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -350,7 +350,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -433,7 +433,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -522,7 +522,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -611,7 +611,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -694,7 +694,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -777,7 +777,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -860,7 +860,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); @@ -979,7 +979,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $counter = 0; do { - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); $counter++; if ($callbackException !== null) { throw($callbackException); diff --git a/tests/Service/Messaging/Mqtt/Cloud/CloudOffboardServiceTest.php b/tests/Service/Messaging/Mqtt/Cloud/CloudOffboardServiceTest.php index 2dfce45..c170ff7 100644 --- a/tests/Service/Messaging/Mqtt/Cloud/CloudOffboardServiceTest.php +++ b/tests/Service/Messaging/Mqtt/Cloud/CloudOffboardServiceTest.php @@ -113,7 +113,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $cloudOnboardParameters->setEndpoints($onboardRequests); $cloudOffboardService->send($cloudOnboardParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/Cloud/CloudOnboardServiceTest.php b/tests/Service/Messaging/Mqtt/Cloud/CloudOnboardServiceTest.php index de579aa..132ee48 100644 --- a/tests/Service/Messaging/Mqtt/Cloud/CloudOnboardServiceTest.php +++ b/tests/Service/Messaging/Mqtt/Cloud/CloudOnboardServiceTest.php @@ -117,7 +117,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $cloudOnboardService->send($cloudOnboardParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/FeedConfirmServiceTest.php b/tests/Service/Messaging/Mqtt/FeedConfirmServiceTest.php index ba6d7d1..9d85243 100644 --- a/tests/Service/Messaging/Mqtt/FeedConfirmServiceTest.php +++ b/tests/Service/Messaging/Mqtt/FeedConfirmServiceTest.php @@ -104,7 +104,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedConfirmParameters->setMessageIds([UuidService::newUuid()]); $feedConfirmService->send($feedConfirmParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -156,7 +156,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedConfirmParameters->setOnboardResponse(self::$onboardResponse); $feedConfirmService->send($feedConfirmParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/FeedDeleteServiceTest.php b/tests/Service/Messaging/Mqtt/FeedDeleteServiceTest.php index adaca56..565b864 100644 --- a/tests/Service/Messaging/Mqtt/FeedDeleteServiceTest.php +++ b/tests/Service/Messaging/Mqtt/FeedDeleteServiceTest.php @@ -106,7 +106,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedDeleteService->send($feedDeleteParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -159,7 +159,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedDeleteParameters->setMessageIds([UuidService::newUuid()]); $feedDeleteService->send($feedDeleteParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -212,7 +212,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedDeleteParameters->setSenders([UuidService::newUuid()]); $feedDeleteService->send($feedDeleteParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -270,7 +270,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $feedDeleteParameters->setValidityPeriod($validityPeriod); $feedDeleteService->send($feedDeleteParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/ListEndpointsServiceTest.php b/tests/Service/Messaging/Mqtt/ListEndpointsServiceTest.php index a414fd6..e340500 100644 --- a/tests/Service/Messaging/Mqtt/ListEndpointsServiceTest.php +++ b/tests/Service/Messaging/Mqtt/ListEndpointsServiceTest.php @@ -95,7 +95,7 @@ protected static function cleanupQueues(bool $cleanupQueues): void $logger = $loggerBuilder->withTestConsoleDefaultValues("TestClassSetup")->build(); $counter = 0; while ($cleanupQueues) { - $cleanupQueues = SleepTimer::letTheAgrirouterProcessTheMqttMessage(2, mqttClient: self::$mqttClient); + $cleanupQueues = SleepTimer::letTheAgrirouterProcessTheMqttMessage(2, self::$mqttClient); if ($cleanupQueues) $counter++; } $logger->info("Cleaned mqtt queue, removed " . $counter . " messages."); @@ -164,7 +164,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $listEndpointsService->send($listEndpointsParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -220,7 +220,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $listEndpointsParameters->setFiltered(true); $listEndpointsService->send($listEndpointsParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/QueryHeadersServiceTest.php b/tests/Service/Messaging/Mqtt/QueryHeadersServiceTest.php index 97a77dd..852dd08 100644 --- a/tests/Service/Messaging/Mqtt/QueryHeadersServiceTest.php +++ b/tests/Service/Messaging/Mqtt/QueryHeadersServiceTest.php @@ -106,7 +106,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryHeadersParameters->setOnboardResponse(self::$onboardResponse); $queryHeadersService->send($queryHeadersParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -153,7 +153,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryHeadersParameters->setMessageIds([UuidService::newUuid()]); $queryHeadersService->send($queryHeadersParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -200,7 +200,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryHeadersParameters->setSenders([UuidService::newUuid()]); $queryHeadersService->send($queryHeadersParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -252,7 +252,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryHeadersParameters->setValidityPeriod($validityPeriod); $queryHeadersService->send($queryHeadersParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/QueryMessagesServiceTest.php b/tests/Service/Messaging/Mqtt/QueryMessagesServiceTest.php index be9124c..033527f 100644 --- a/tests/Service/Messaging/Mqtt/QueryMessagesServiceTest.php +++ b/tests/Service/Messaging/Mqtt/QueryMessagesServiceTest.php @@ -106,7 +106,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryMessagesParameters->setOnboardResponse(self::$onboardResponse); $queryHeadersService->send($queryMessagesParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -153,7 +153,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryMessagesParameters->setMessageIds([UuidService::newUuid()]); $queryHeadersService->send($queryMessagesParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -200,7 +200,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryMessagesParameters->setSenders([UuidService::newUuid()]); $queryHeadersService->send($queryMessagesParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -252,7 +252,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $queryMessagesParameters->setValidityPeriod($validityPeriod); $queryHeadersService->send($queryMessagesParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } diff --git a/tests/Service/Messaging/Mqtt/SubscriptionServiceTest.php b/tests/Service/Messaging/Mqtt/SubscriptionServiceTest.php index 89217d9..2241036 100644 --- a/tests/Service/Messaging/Mqtt/SubscriptionServiceTest.php +++ b/tests/Service/Messaging/Mqtt/SubscriptionServiceTest.php @@ -84,7 +84,7 @@ protected static function cleanupQueues(bool $cleanupQueues): void $logger = $loggerBuilder->withTestConsoleDefaultValues("TestClassSetup")->build(); $counter = 0; while ($cleanupQueues) { - $cleanupQueues = SleepTimer::letTheAgrirouterProcessTheMqttMessage(2, mqttClient: self::$mqttClient); + $cleanupQueues = SleepTimer::letTheAgrirouterProcessTheMqttMessage(2, self::$mqttClient); if ($cleanupQueues) $counter++; } $logger->info("Cleaned mqtt queue, removed " . $counter . " messages."); @@ -156,7 +156,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $subscriptionParameters->setSubscriptionItems($subscriptionItems); $subscriptionService->send($subscriptionParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } @@ -202,7 +202,7 @@ function (string $topic, string $message) use (&$mqttClient, &$logger, &$callbac $subscriptionParameters->setSubscriptionItems($subscriptionItems); $subscriptionService->send($subscriptionParameters); - self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(mqttClient: self::$mqttClient)); + self::assertTrue(SleepTimer::letTheAgrirouterProcessTheMqttMessage(3, self::$mqttClient)); if ($callbackException !== null) { throw($callbackException); } From ddd8ed2df567d49c11cd3dbad45cd61b22bd1243 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Wed, 28 Jul 2021 12:06:47 +0300 Subject: [PATCH 10/22] Set default array to OutboxResponse messages in order to fix error accessing before initialization --- src/Dto/Messaging/Http/OutboxResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dto/Messaging/Http/OutboxResponse.php b/src/Dto/Messaging/Http/OutboxResponse.php index 73dfc80..635b09b 100644 --- a/src/Dto/Messaging/Http/OutboxResponse.php +++ b/src/Dto/Messaging/Http/OutboxResponse.php @@ -12,7 +12,7 @@ class OutboxResponse implements JsonDeserializableInterface { private string $statusCode; - private array $messages; + private array $messages = []; /** * @param mixed[]|string $jsonData From 87c861edbe33ef83476802247e7486e61bf1d169 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 09:17:36 +0300 Subject: [PATCH 11/22] Added support of sending Metadata --- src/Service/Common/EncodeMessageService.php | 1 + src/Service/Parameters/MessageHeaderParameters.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Service/Common/EncodeMessageService.php b/src/Service/Common/EncodeMessageService.php index 14625ae..9895be3 100644 --- a/src/Service/Common/EncodeMessageService.php +++ b/src/Service/Common/EncodeMessageService.php @@ -42,6 +42,7 @@ private function encodeHeader(MessageHeaderParameters $messageHeaderParameters): $requestEnvelope->setTechnicalMessageType($messageHeaderParameters->getTechnicalMessageType()); $requestEnvelope->setMode($messageHeaderParameters->getMode()); $requestEnvelope->setTimestamp(UtcDataService::nowAsTimestamp()); + $requestEnvelope->setMetadata($messageHeaderParameters->getMetadata()); return $requestEnvelope; } diff --git a/src/Service/Parameters/MessageHeaderParameters.php b/src/Service/Parameters/MessageHeaderParameters.php index c11795c..13ea234 100644 --- a/src/Service/Parameters/MessageHeaderParameters.php +++ b/src/Service/Parameters/MessageHeaderParameters.php @@ -3,6 +3,7 @@ namespace App\Service\Parameters { use Agrirouter\Commons\ChunkComponent; + use Agrirouter\Commons\Metadata; use App\Api\Service\Parameters\Parameters; use App\Api\Service\Parameters\ValidatableInterface; @@ -17,6 +18,7 @@ class MessageHeaderParameters extends Parameters implements ValidatableInterface private string $teamSetContextId; private array $recipients; private ChunkComponent $chunkComponent; + private ?Metadata $metadata; public function validate(): void { @@ -73,6 +75,14 @@ public function setChunkComponent(ChunkComponent $chunkComponent): void $this->chunkComponent = $chunkComponent; } + public function getMetadata(): ?Metadata + { + return $this->metadata; + } + public function setMetadata(Metadata $metadata): void + { + $this->metadata = $metadata; + } } } \ No newline at end of file From c5cae954630be9e01378a1e126b3f574160863a1 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 09:17:36 +0300 Subject: [PATCH 12/22] Added support of sending Metadata --- src/Service/Common/EncodeMessageService.php | 1 + src/Service/Parameters/MessageHeaderParameters.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Service/Common/EncodeMessageService.php b/src/Service/Common/EncodeMessageService.php index 14625ae..9895be3 100644 --- a/src/Service/Common/EncodeMessageService.php +++ b/src/Service/Common/EncodeMessageService.php @@ -42,6 +42,7 @@ private function encodeHeader(MessageHeaderParameters $messageHeaderParameters): $requestEnvelope->setTechnicalMessageType($messageHeaderParameters->getTechnicalMessageType()); $requestEnvelope->setMode($messageHeaderParameters->getMode()); $requestEnvelope->setTimestamp(UtcDataService::nowAsTimestamp()); + $requestEnvelope->setMetadata($messageHeaderParameters->getMetadata()); return $requestEnvelope; } diff --git a/src/Service/Parameters/MessageHeaderParameters.php b/src/Service/Parameters/MessageHeaderParameters.php index c394486..ce107d1 100644 --- a/src/Service/Parameters/MessageHeaderParameters.php +++ b/src/Service/Parameters/MessageHeaderParameters.php @@ -3,6 +3,7 @@ namespace App\Service\Parameters { use Agrirouter\Commons\ChunkComponent; + use Agrirouter\Commons\Metadata; use App\Api\Service\Parameters\Parameters; use App\Api\Service\Parameters\ValidatableInterface; @@ -20,7 +21,7 @@ class MessageHeaderParameters extends Parameters implements ValidatableInterface */ private ?array $recipients = null; private ?ChunkComponent $chunkComponent = null; - + private ?Metadata $metadata; public function validate(): void { // TODO: Implement validate() method. @@ -81,5 +82,15 @@ public function setChunkComponent(ChunkComponent $chunkComponent): void { $this->chunkComponent = $chunkComponent; } + + public function getMetadata(): ?Metadata + { + return $this->metadata; + } + + public function setMetadata(Metadata $metadata): void + { + $this->metadata = $metadata; + } } } From 5e9790120ec29deb5fa37c7214f513261b115052 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 10:35:27 +0300 Subject: [PATCH 13/22] Fixed construction of AuthorizationResult --- src/Dto/Onboard/AuthorizationResult.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Dto/Onboard/AuthorizationResult.php b/src/Dto/Onboard/AuthorizationResult.php index 6837618..71ad5c9 100644 --- a/src/Dto/Onboard/AuthorizationResult.php +++ b/src/Dto/Onboard/AuthorizationResult.php @@ -13,6 +13,12 @@ class AuthorizationResult private ?string $token = null; private ?string $error = null; + public function __construct(?string $authorizationUrl, ?string $state) + { + $this->authorizationUrl = $authorizationUrl; + $this->state = $state; + } + public function getState(): ?string { return $this->state; From bdbf21cc8d037b6dce8431424e31035695dad556 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 11:03:24 +0300 Subject: [PATCH 14/22] Removed wrong constructor from AuthorizationResult. Added constructor method to AuthorizationUrlResult.php --- src/Dto/Onboard/AuthorizationResult.php | 6 ------ src/Dto/Onboard/AuthorizationUrlResult.php | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Dto/Onboard/AuthorizationResult.php b/src/Dto/Onboard/AuthorizationResult.php index 71ad5c9..6837618 100644 --- a/src/Dto/Onboard/AuthorizationResult.php +++ b/src/Dto/Onboard/AuthorizationResult.php @@ -13,12 +13,6 @@ class AuthorizationResult private ?string $token = null; private ?string $error = null; - public function __construct(?string $authorizationUrl, ?string $state) - { - $this->authorizationUrl = $authorizationUrl; - $this->state = $state; - } - public function getState(): ?string { return $this->state; diff --git a/src/Dto/Onboard/AuthorizationUrlResult.php b/src/Dto/Onboard/AuthorizationUrlResult.php index 8701314..f658bc9 100644 --- a/src/Dto/Onboard/AuthorizationUrlResult.php +++ b/src/Dto/Onboard/AuthorizationUrlResult.php @@ -11,6 +11,13 @@ class AuthorizationUrlResult private ?string $authorizationUrl = null; private ?string $state = null; + public function __construct(?string $authorizationUrl, ?string $state) + { + $this->authorizationUrl = $authorizationUrl; + $this->state = $state; + } + + public function getAuthorizationUrl(): ?string { return $this->authorizationUrl; From df770cf77feb575819b4c2e50966b0ac12966a02 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 15:07:24 +0300 Subject: [PATCH 15/22] Fixed accessing before initialization in MessageHeaderParameters --- src/Service/Parameters/MessageHeaderParameters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/Parameters/MessageHeaderParameters.php b/src/Service/Parameters/MessageHeaderParameters.php index 77e9a86..f1f10ca 100644 --- a/src/Service/Parameters/MessageHeaderParameters.php +++ b/src/Service/Parameters/MessageHeaderParameters.php @@ -21,7 +21,7 @@ class MessageHeaderParameters extends Parameters implements ValidatableInterface */ private ?array $recipients = null; private ?ChunkComponent $chunkComponent = null; - private ?Metadata $metadata; + private ?Metadata $metadata = null; public function validate(): void { From 6a759ace912a7a3811ff02d929bc7ef06cb14f9e Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 15:11:59 +0300 Subject: [PATCH 16/22] Fixed UtcDataService::now --- src/Service/Common/UtcDataService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/Common/UtcDataService.php b/src/Service/Common/UtcDataService.php index 90bdfa5..0074d2a 100644 --- a/src/Service/Common/UtcDataService.php +++ b/src/Service/Common/UtcDataService.php @@ -21,7 +21,7 @@ class UtcDataService */ public static function now(): string { - $d = new DateTime(null, new DateTimeZone('UTC')); + $d = new DateTime('now', new DateTimeZone('UTC')); return $d->format("Y-m-d\TH:i:s.v\Z"); } From babeb98a0b35c98ae9b37fc0e12154f47d8d6436 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 16 Aug 2021 15:34:27 +0300 Subject: [PATCH 17/22] Implemented sending chunk info --- src/Service/Common/EncodeMessageService.php | 1 + src/Service/Parameters/MessageHeaderParameters.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Service/Common/EncodeMessageService.php b/src/Service/Common/EncodeMessageService.php index 9895be3..6bf7597 100644 --- a/src/Service/Common/EncodeMessageService.php +++ b/src/Service/Common/EncodeMessageService.php @@ -43,6 +43,7 @@ private function encodeHeader(MessageHeaderParameters $messageHeaderParameters): $requestEnvelope->setMode($messageHeaderParameters->getMode()); $requestEnvelope->setTimestamp(UtcDataService::nowAsTimestamp()); $requestEnvelope->setMetadata($messageHeaderParameters->getMetadata()); + $requestEnvelope->setChunkInfo($messageHeaderParameters->getChunkComponent()); return $requestEnvelope; } diff --git a/src/Service/Parameters/MessageHeaderParameters.php b/src/Service/Parameters/MessageHeaderParameters.php index f1f10ca..a253deb 100644 --- a/src/Service/Parameters/MessageHeaderParameters.php +++ b/src/Service/Parameters/MessageHeaderParameters.php @@ -74,7 +74,7 @@ public function setRecipients(array $recipients): void $this->recipients = $recipients; } - public function getChunkComponent(): ChunkComponent + public function getChunkComponent(): ?ChunkComponent { return $this->chunkComponent; } From 3af0932be092abc249ca877d95f172be89d647c8 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Wed, 18 Aug 2021 14:11:06 +0300 Subject: [PATCH 18/22] Fixed typing error in OutboxResponse --- src/Dto/Messaging/Http/OutboxResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dto/Messaging/Http/OutboxResponse.php b/src/Dto/Messaging/Http/OutboxResponse.php index 48cb468..49b73ce 100644 --- a/src/Dto/Messaging/Http/OutboxResponse.php +++ b/src/Dto/Messaging/Http/OutboxResponse.php @@ -37,7 +37,7 @@ public function jsonDeserialize($jsonData): JsonDeserializableInterface return $this; } - public function getStatusCode(): string + public function getStatusCode(): ?string { return $this->statusCode; } @@ -50,7 +50,7 @@ public function setStatusCode(string $statusCode): void /** * @return OutboxMessage[] */ - public function getMessages(): array + public function getMessages(): ?array { return $this->messages; } From ec5ef40d46285f4c93d193ee4cf5fc0329b008bc Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Fri, 3 Sep 2021 13:38:20 +0300 Subject: [PATCH 19/22] Added nullable type hint for ListEndpointsParameters in order to prevent errors --- src/Service/Parameters/ListEndpointsParameters.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/Parameters/ListEndpointsParameters.php b/src/Service/Parameters/ListEndpointsParameters.php index 8825998..201ebdc 100644 --- a/src/Service/Parameters/ListEndpointsParameters.php +++ b/src/Service/Parameters/ListEndpointsParameters.php @@ -15,7 +15,7 @@ class ListEndpointsParameters extends MessageParameters private ?string $direction = null; private bool $filtered = false; - public function getTechnicalMessageType(): string + public function getTechnicalMessageType(): ?string { return $this->technicalMessageType; } @@ -25,7 +25,7 @@ public function setTechnicalMessageType(string $technicalMessageType): void $this->technicalMessageType = $technicalMessageType; } - public function getDirection(): string + public function getDirection(): ?string { return $this->direction; } From 263f26b2c54673361007d1526bb3bb826edb4bf6 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 6 Sep 2021 16:12:38 +0300 Subject: [PATCH 20/22] Fixed setting recipients in EncodeMessageService --- src/Service/Common/EncodeMessageService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Service/Common/EncodeMessageService.php b/src/Service/Common/EncodeMessageService.php index 6bf7597..1634a5f 100644 --- a/src/Service/Common/EncodeMessageService.php +++ b/src/Service/Common/EncodeMessageService.php @@ -40,6 +40,7 @@ private function encodeHeader(MessageHeaderParameters $messageHeaderParameters): $requestEnvelope->setApplicationMessageId(empty($messageHeaderParameters->getApplicationMessageId()) ? UuidService::newUuid() : $messageHeaderParameters->getApplicationMessageId()); $requestEnvelope->setApplicationMessageSeqNo($messageHeaderParameters->getApplicationMessageSeqNo()); $requestEnvelope->setTechnicalMessageType($messageHeaderParameters->getTechnicalMessageType()); + $requestEnvelope->setRecipients($messageHeaderParameters->getRecipients()); $requestEnvelope->setMode($messageHeaderParameters->getMode()); $requestEnvelope->setTimestamp(UtcDataService::nowAsTimestamp()); $requestEnvelope->setMetadata($messageHeaderParameters->getMetadata()); From 9ffb69e64e7c8286cde9a2ed89a924dad4d3e90d Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 6 Sep 2021 16:36:49 +0300 Subject: [PATCH 21/22] Fixed setting recipients in EncodeMessageService for publish mode --- src/Service/Common/EncodeMessageService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Service/Common/EncodeMessageService.php b/src/Service/Common/EncodeMessageService.php index 1634a5f..a183022 100644 --- a/src/Service/Common/EncodeMessageService.php +++ b/src/Service/Common/EncodeMessageService.php @@ -40,7 +40,10 @@ private function encodeHeader(MessageHeaderParameters $messageHeaderParameters): $requestEnvelope->setApplicationMessageId(empty($messageHeaderParameters->getApplicationMessageId()) ? UuidService::newUuid() : $messageHeaderParameters->getApplicationMessageId()); $requestEnvelope->setApplicationMessageSeqNo($messageHeaderParameters->getApplicationMessageSeqNo()); $requestEnvelope->setTechnicalMessageType($messageHeaderParameters->getTechnicalMessageType()); - $requestEnvelope->setRecipients($messageHeaderParameters->getRecipients()); + $recipients = $messageHeaderParameters->getRecipients(); + if (!empty($recipients)) { + $requestEnvelope->setRecipients($messageHeaderParameters->getRecipients()); + } $requestEnvelope->setMode($messageHeaderParameters->getMode()); $requestEnvelope->setTimestamp(UtcDataService::nowAsTimestamp()); $requestEnvelope->setMetadata($messageHeaderParameters->getMetadata()); From e893f17b7cf4de6a2f3ece0d14457199dbe10430 Mon Sep 17 00:00:00 2001 From: Ivan Hermanov Date: Mon, 6 Sep 2021 16:38:28 +0300 Subject: [PATCH 22/22] Fixed MessageHeaderParameters.getRecipients for null --- src/Service/Parameters/MessageHeaderParameters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/Parameters/MessageHeaderParameters.php b/src/Service/Parameters/MessageHeaderParameters.php index a253deb..0a93862 100644 --- a/src/Service/Parameters/MessageHeaderParameters.php +++ b/src/Service/Parameters/MessageHeaderParameters.php @@ -61,7 +61,7 @@ public function setTeamSetContextId(string $teamSetContextId): void /** * @return string[] */ - public function getRecipients(): array + public function getRecipients(): ?array { return $this->recipients; }